【问题标题】:Removing auto <p> tag from Advanced Custom Fields in Wordpress BUT keeping the <br> tags从 Wordpress 中的高级自定义字段中删除自动 <p> 标签,但保留 <br> 标签
【发布时间】:2020-08-14 22:56:44
【问题描述】:

我在 Wordpress 中使用此过滤器从 ACF 的文本区域中删除自动“p”标签:

    function acf_wysiwyg_remove_wpautop() {

       remove_filter('acf_the_content', 'wpautop' );
       }

    add_action('acf/init', 'acf_wysiwyg_remove_wpautop');

它工作得非常好,并删除了包装“p”标签,但它也删除了“br”标签。

如何保留“br”标签,以便我仍然可以在 ACF 文本区域中进行换行?

感谢您的帮助!

【问题讨论】:

    标签: wordpress filter tags textarea advanced-custom-fields


    【解决方案1】:

    您可以使用 no line to break 功能来做到这一点:

    function acf_wysiwyg_remove_wpautop() {
      // remove p tags //
      remove_filter('acf_the_content', 'wpautop' );
      // add line breaks before all newlines //
      add_filter( 'acf_the_content', 'nl2br' );
    }
    
    add_action('acf/init', 'acf_wysiwyg_remove_wpautop');
    

    使用最新的 ACF 在最新的 WordPress 上测试。

    【讨论】:

      猜你喜欢
      • 2013-09-17
      • 1970-01-01
      • 2011-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-23
      • 2018-05-19
      • 1970-01-01
      相关资源
      最近更新 更多