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

Removing auto <p> tag from Advanced Custom Fields in Wordpress BUT keeping the <br> tags

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

感谢您的帮助!

您可以使用无换行功能来​​做到这一点:

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 上进行了测试。