Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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-删除特定自定义帖子类型的自动生成段落_Wordpress - Fatal编程技术网

Wordpress-删除特定自定义帖子类型的自动生成段落

Wordpress-删除特定自定义帖子类型的自动生成段落,wordpress,Wordpress,我在Wordpress中生成了一些自定义的帖子类型,需要在帖子中添加一些html代码。问题是wordpress在我的代码中添加了一些令人讨厌的段落,这打破了我的思路。有没有办法删除wordpress为此特定帖子类型生成的额外段落 我为帖子和单个posttype.php文件使用一个自定义循环,因此我可以完全控制一般输出。您可以通过将其放入主题的functions.php中来删除内容上的wpautop筛选器,方法如下: remove_filter('the_content','wpautop');

我在Wordpress中生成了一些自定义的帖子类型,需要在帖子中添加一些html代码。问题是wordpress在我的代码中添加了一些令人讨厌的段落,这打破了我的思路。有没有办法删除wordpress为此特定帖子类型生成的额外段落


我为帖子和单个posttype.php文件使用一个自定义循环,因此我可以完全控制一般输出。

您可以通过将其放入主题的functions.php中来删除内容上的wpautop筛选器,方法如下:

remove_filter('the_content','wpautop');

//decide when you want to apply the auto paragraph

add_filter('the_content','my_custom_formatting');

function my_custom_formatting($content){
if(get_post_type()=='my_custom_post') //if it does not work, you may want to pass the current post object to get_post_type
    return $content;//no autop
else
 return wpautop($content);
}

您可以通过如下操作将其放入主题的functions.php中,删除内容上的wpautop筛选器:

remove_filter('the_content','wpautop');

//decide when you want to apply the auto paragraph

add_filter('the_content','my_custom_formatting');

function my_custom_formatting($content){
if(get_post_type()=='my_custom_post') //if it does not work, you may want to pass the current post object to get_post_type
    return $content;//no autop
else
 return wpautop($content);
}

这起作用了。只是不喜欢这样,您必须完整地删除wpautop,然后再将其添加回来。不管怎样,这很有效。只是不喜欢这样,您必须完整地删除wpautop,然后再将其添加回来。无论如何