Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 删除自动<;p>;从除帖子以外的所有内容_Wordpress - Fatal编程技术网

Wordpress 删除自动<;p>;从除帖子以外的所有内容

Wordpress 删除自动<;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');

我使用这段代码来删除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');

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
}

谢谢,马特,这是漫长的一天