[英]Removing auto <p> tag from Advanced Custom Fields in Wordpress BUT keeping the <br> tags
I'm using this filter in Wordpress to remove the auto 'p' tags from ACF's text areas:我在 Wordpress 中使用此过滤器从 ACF 的文本区域中删除自动“p”标签:
function acf_wysiwyg_remove_wpautop() {
remove_filter('acf_the_content', 'wpautop' );
}
add_action('acf/init', 'acf_wysiwyg_remove_wpautop');
It's working perfectly fine and removes the wrapping 'p' tag but it's also removing 'br' tags.它工作得很好,并删除了包装“p”标签,但它也删除了“br”标签。
How can I keep the 'br' tags so I can still make line breaks in ACF text areas?如何保留“br”标签,以便仍然可以在 ACF 文本区域中进行换行?
Thanks for your help!谢谢你的帮助!
You can do this by using the no line to break function:您可以通过使用 no 行打破 function 来做到这一点:
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');
Tested on the latest WordPress with the latest ACF.使用最新的 ACF 在最新的 WordPress 上进行测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.