要对嵌套标题使用不同的回调,请在pricing_box
在返回字符串之前,回调并还原主处理程序。
add_shortcode( \'pricing_box\', \'shortcode_pricing_box\' );
add_shortcode( \'heading\', \'shortcode_heading_main\' );
function shortcode_pricing_box( $atts, $content = \'\' )
{
// switch shortcode handlers
add_shortcode( \'heading\', \'shortcode_heading_pricing_box\' );
$out = \'<div class="pricing-box">\' . do_shortcode( $content ) . \'</div>\';
// restore main handler
add_shortcode( \'heading\', \'shortcode_heading_main\' );
return $out;
}
function shortcode_heading_main( $atts, $content = \'\' )
{
return "<h2>$content</h2>";
}
function shortcode_heading_pricing_box( $atts, $content = \'\' )
{
return "<h3>$content</h3>";
}