我在 Wordpress 中生成了一些自定义帖子类型,我需要在其中向帖子添加一些 html 代码。问题是 wordpress 在我的代码中添加了一些令人讨厌的段落,它打断了我的台词。有什么方法可以删除 wordpress 为这种特定帖子类型生成的额外段落吗?
我为帖子和 single-posttype.php 文件使用自定义循环,因此我可以完全控制一般输出。
最佳答案
您可以删除内容上的 wpautop 过滤器,方法是将其放入主题的 functions.php 中,方法如下:
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);
}
https://stackoverflow.com/questions/7697465/