【发布时间】:2018-12-02 01:18:38
【问题描述】:
我在 Wordpress 中生成了一些自定义帖子类型,我需要在帖子中添加一些 html 代码。问题是 wordpress 在我的代码中添加了一些讨厌的段落,它打破了我的界限。有什么方法可以删除 wordpress 为这种特定帖子类型生成的额外段落?
我对帖子和单个 posttype.php 文件使用自定义循环,因此我可以完全控制一般输出。
【问题讨论】:
标签: wordpress
我在 Wordpress 中生成了一些自定义帖子类型,我需要在帖子中添加一些 html 代码。问题是 wordpress 在我的代码中添加了一些讨厌的段落,它打破了我的界限。有什么方法可以删除 wordpress 为这种特定帖子类型生成的额外段落?
我对帖子和单个 posttype.php 文件使用自定义循环,因此我可以完全控制一般输出。
【问题讨论】:
标签: wordpress
您可以通过将其放入主题的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);
}
【讨论】: