Wordpress嵌套的短代码无效

时间:2013-01-28 23:10:26

标签: wordpress nested shortcode

您好我正在尝试将grid.css文件转换为wordpress短代码但是我遇到了问题。

我想看到的内容:

<div class="row>
    <div class="columns one">Content</div>
    <div class="columns three">Content</div>
</div>

我得到了什么:

[column_one]Awesome[/column_one] [column_three]Stuff[/column_three]

我的代码:

<?php while ( have_posts() ) : the_post();
$content = get_the_content();
echo do_shortcode($content);
endwhile; // end of the loop. ?>

我在一个简单的页面模板上尝试这个。

如何让它正常运作?

谢谢。

1 个答案:

答案 0 :(得分:1)

您不需要在循环中添加do_shortcode。更好的是将它添加到functions.php文件中,如下所示:

function column_one( $atts, $content = null ) {
    return '<div class="columns one">'.do_shortcode($content).'</div>';
}

add_shortcode('column_one', 'column_one');