是的,您可以继续嵌套短代码。只要继续使用do_shortcode()
直到到达最深处。https://codex.wordpress.org/Shortcode_API#Nested_Shortcodes
所以你可以这样做,
[container]
[other_column class="extra-class"]
[content]
col 1
[/content]
[another]
col 1-2
[/another]
[/other_column]
[column]
[another]
col 2
[/another]
[/column]
[/container]
要实现这样的输出,
<div class="container">
<div class="other-column extra-class">
<div class="content">
col 1
</div>
<div class="another">
col 1-2
</div>
</div>
<div class="column">
<div class="another">
col 2
</div>
</div>
</div>
如果您有这样的短代码函数。如果您需要,我提供了一个属性示例。
function container_shortcode($atts = array(), $content = null) {
return \'<div class="container">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode( \'container\', \'container_shortcode\' );
function column_shortcode($atts = array(), $content = null) {
return \'<div class="column">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode( \'column\', \'column_shortcode\' );
function other_column_shortcode($atts = array(), $content = null) {
$defaults = array(
\'class\' => \'\',
);
$atts = shortcode_atts( $defaults, $atts, \'other_column_shortcode\' );
$class = (! empty($atts[\'class\']) ) ? \'other-column \' . $atts[\'class\'] : \'other-column\';
return \'<div class="\' . esc_attr($class) . \'">\' . do_shortcode($content) . \'</div>\';
}
add_shortcode( \'other_column\', \'other_column_shortcode\' );
function content_shortcode($atts = array(), $content=null) {
return \'<div class="content">\' . $content . \'</div>\';
}
add_shortcode( \'content\', \'content_shortcode\' );
function another_shortcode($atts = array(), $content=null) {
return \'<div class="another">\' . $content . \'</div>\';
}
add_shortcode( \'another\', \'another_shortcode\' );