使用短代码显示WordPress页面内容并显示嵌入式短代码

我正在使用自定义帖子类型在网站上显示横幅。内容可以是文本, 图像以及简码(例如按钮简码)。
如果使用短代码显示内容, 则一切看起来都可以找到。横幅本身内的短代码除外。
有什么办法可以渲染该短代码?
这是我的shordcode:

// [banner id="" class=""] function shortcode_banner( $atts, $content ){ extract(shortcode_atts(array( 'id'=> '', 'class' => '', ), $atts)); $banner_id= $id; $content= get_post_field('post_content', $banner_id); return '< div class="'.$class.'"> '.wpautop($content).'< /div> '; } add_shortcode( 'banner', 'shortcode_banner' );

#1试试下面的代码:
// [banner id="" class=""] function shortcode_banner( $atts, $content ) { extract(shortcode_atts( array( 'id'=> '', 'class' => '', ), $atts ) ); $banner_id = $id; $content= get_post_field( 'post_content', $banner_id ); return '< div class="'.$class.'"> '.wpautop( do_shortcode( $content ) ).'< /div> '; }

或者, 如果你希望使用递归短代码:
function recursively_do_shortcode( $content ) { $content2 = $content; do{ $content = $content2; $content2 = do_shortcode( $content ); } while( $content2 !== $content ); // presumably you can test if shortcodes exist in content as well return $content2; }// [banner id="" class=""] function shortcode_banner( $atts, $content ){ extract( shortcode_atts( array( 'id'=> '', 'class' => '', ), $atts ) ); $banner_id = $id; $content= get_post_field( 'post_content', $banner_id ); return '< div class="'.$class.'"> '.wpautop( recursively_do_shortcode( $content ) ).'< /div> '; }

【使用短代码显示WordPress页面内容并显示嵌入式短代码】参考:do_shortcode

    推荐阅读