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

我在 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/

相关文章:

php - 如何在 codeigniter form_validation 类中允许空值或数值?

MongoDB - 添加到集合并递增

asp.net-mvc - 在 Razor 模板引擎上打印可空类型

assembly - 如何正确结束 assembly ?

geodjango - Django-profiles,带有地理字段的用户配置文件?

web-services - 对于可能返回过时数据的 GET 请求,我应该使用什么 HTTP 状态代

spring - 通过 spring 注释进行的交易 - 只读与否?

architecture - Java中的模块、插件和组件有什么区别?

perl - 这个 zip 命令是如何在 perl 中使用的?

sql-server - 检查是否启用了复制