【问题标题】:Wordpress - Remove auto generated paragraphs for specific custom post typeWordpress - 删除特定自定义帖子类型的自动生成段落
【发布时间】:2018-12-02 01:18:38
【问题描述】:

我在 Wordpress 中生成了一些自定义帖子类型,我需要在帖子中添加一些 html 代码。问题是 wordpress 在我的代码中添加了一些讨厌的段落,它打破了我的界限。有什么方法可以删除 wordpress 为这种特定帖子类型生成的额外段落?

我对帖子和单个 posttype.php 文件使用自定义循环,因此我可以完全控制一般输出。

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    您可以通过将其放入主题的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,然后再将其添加回来。无论如何。
    猜你喜欢
    • 2020-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-29
    相关资源
    最近更新 更多