Wordpress 删除自动<;p>;从除帖子以外的所有内容
我使用这段代码来删除wp生成的autopWordpress 删除自动<;p>;从除帖子以外的所有内容,wordpress,Wordpress,我使用这段代码来删除wp生成的autop remove_filter('the_content', 'wpautop'); 一切都很好,但我只需要在博客文章中使用autop 在搜索之后,我发现我可以检测到这是否是一篇文章,混合了另一个问题和wp-doc提出的这个问题,直到Matt指出错误才起作用。 以下代码在wp 4.7.3上正常工作 remove_filter('the_content','wpautop'); add_filter('the_content','if_is_post');
remove_filter('the_content', 'wpautop');
一切都很好,但我只需要在博客文章中使用autop
在搜索之后,我发现我可以检测到这是否是一篇文章,混合了另一个问题和wp-doc提出的这个问题,直到Matt指出错误才起作用。
以下代码在wp 4.7.3上正常工作
remove_filter('the_content','wpautop');
add_filter('the_content','if_is_post');
function if_is_post($content){
if(is_singular('post'))
return wpautop($content);
else
return $content;//no autop
}
如果希望只在POST中应用wpautop筛选器,则If语句是向后的。现在,您正在移除过滤器,如果当前的帖子类型是post,它将保持移除状态。相信你的代码应该是这样的
remove_filter('the_content','wpautop');
add_filter('the_content','if_is_post');
function if_is_post($content){
if(is_singular('post'))
return wpautop($content);
else
return $content;//no autop
}
谢谢,马特,这是漫长的一天