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