我在Wordpress中生成了一些自定义帖子类型,我需要在帖子中添加一些HTML代码.问题是wordpress在我的代码中添加了一些令人讨厌的段落,它破坏了我的界限.有没有办法删除wordpress为这个特定的帖子类型生成的额外段落?
我使用自定义循环的帖子和单posttypetype.php文件,所以我完全控制一般输出.
小智 11
您可以通过将此内容放入主题的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);
}
Run Code Online (Sandbox Code Playgroud)