在Wordpress中删除高级自定义字段中的自动<p>标签,但保留<br>标签。

问题描述 投票:0回答:1

我在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文本区域中进行换行?

谢谢您的帮助!我在Word中使用这个过滤器。

wordpress filter tags textarea advanced-custom-fields
1个回答
0
投票

你可以通过使用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');

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

© www.soinside.com 2019 - 2024. All rights reserved.