我通过结合来自 Donal MacArthur 的稍微修改的 parse_shortcode_content 函数(他最初手动调用 wpautop...,我已将其删除)尽可能地解决了这个问题。重新排序默认过滤器以稍后运行 wpautop.. . 在短代码已经被处理之后而不是之前。
// Clean up WordPress shortcode sormatting - important for nested shortcodes
// Adjusted from http://donalmacarthur.com/articles/cleaning-up-wordpress-shortcode-formatting/
function parse_shortcode_content( $content ) {
/* Parse nested shortcodes and add formatting. */
$content = trim( do_shortcode( shortcode_unautop( $content ) ) );
/* Remove '' from the start of the string. */
if ( substr( $content, 0, 4 ) == '' )
$content = substr( $content, 4 );
/* Remove '' from the end of the string. */
if ( substr( $content, -3, 3 ) == '' )
$content = substr( $content, 0, -3 );
/* Remove any instances of ''. */
$content = str_replace( array( '<p></p>' ), '', $content );
$content = str_replace( array( '<p> </p>' ), '', $content );
return $content;
}
并移动过滤器
// Move wpautop filter to AFTER shortcode is processed
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop', 99);
add_filter( 'the_content', 'shortcode_unautop', 100 );
编辑:
不再需要parse_shortcode_content() 函数(如果曾经需要的话)。只需调整过滤器顺序。