理论很简单-你只需抓住the_content 优先级高于其他插件处理程序的过滤器:
add_filter(\'the_content\', \'insert_my_sidebar\', 9);
然后进来
insert_my_sidebar 插入侧栏的函数。
但有一个警告-实际上不仅用户插件,而且默认过滤器的优先级为10。因此,默认情况下,无法区分它们。您必须隐式地取消设置默认过滤器,并以高于您的优先级重新设置它们。
remove_filter( \'the_content\', \'wptexturize\' );
remove_filter( \'the_content\', \'convert_smilies\' );
remove_filter( \'the_content\', \'convert_chars\' );
remove_filter( \'the_content\', \'wpautop\' );
remove_filter( \'the_content\', \'shortcode_unautop\' );
remove_filter( \'the_content\', \'prepend_attachment\' );
然后:
add_filter( \'the_content\', \'wptexturize\', 8 );
add_filter( \'the_content\', \'convert_smilies\', 8 );
add_filter( \'the_content\', \'convert_chars\', 8 );
add_filter( \'the_content\', \'wpautop\' , 8 );
add_filter( \'the_content\', \'shortcode_unautop\', 8 );
add_filter( \'the_content\', \'prepend_attachment\', 8 );
你显然应该在
the_content 具有更高优先级的过滤器,如7:)
UPDATE:
完整示例:
add_filter( \'the_content\', \'prepare_to_insert_my_sidebar\', 7);
function prepare_to_insert_my_sidebar($content)
{
remove_filter( \'the_content\', \'wptexturize\' );
remove_filter( \'the_content\', \'convert_smilies\' );
remove_filter( \'the_content\', \'convert_chars\' );
remove_filter( \'the_content\', \'wpautop\' );
remove_filter( \'the_content\', \'shortcode_unautop\' );
remove_filter( \'the_content\', \'prepend_attachment\' );
add_filter( \'the_content\', \'wptexturize\', 8 );
add_filter( \'the_content\', \'convert_smilies\', 8 );
add_filter( \'the_content\', \'convert_chars\', 8 );
add_filter( \'the_content\', \'wpautop\' , 8 );
add_filter( \'the_content\', \'shortcode_unautop\', 8 );
add_filter( \'the_content\', \'prepend_attachment\', 8 );
add_filter(\'the_content\', \'insert_my_sidebar\', 9);
return $content;
}
function insert_my_sidebar($content)
{
ob_start();
dynamic_sidebar(\'name_of_your_sidebar\');
$content .= ob_get_clean();
return $content;
}