This jQuery solution works (it finds the empty <p>
(even if it has whitespace i.e. <p> </p>
and adds inline style: <p style="display:none;"> </p>
. Not the most elegant solution but will do until browsers start supporting CSS4 :blank
pseudo-selector.
jQuery(document).ready(function($) {
$(‘p’).each(function(){
if($.trim($(this).text()) == ” && $(this).children().length == 0){
$(this).hide();
}
});
});
Not my solution. Author is: TNTitan89 and you can find the code at https://jsfiddle.net/TNTitan89/crejkbxq/
You could add a filter to remove them, there is an example here for WP and this could easily be adapted to ACf using an acf/format_value filter for wysiwyg fields https://www.advancedcustomfields.com/resources/acfformat_value/
Thanks John – however, a detailed solution came through (which I think you were pointing me towards) from James on [email protected] which does exactly what I want. Code is (to put in [theme]/functions.php) :
function my_acf_load_value( $value, $post_id, $field ) {
$content = apply_filters('the_content',$value);
$content = force_balance_tags( $content );
$content = preg_replace( '#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content );
$content = preg_replace( '~\s?<p>(\s| )+</p>\s?~', '', $content );
return $content;
}
add_filter('acf/load_value/type=wysiwyg', 'my_acf_load_value', 10, 3);
No more empty <p> tags in ACF Wysisyg fields!
This reply has been marked as private.
thank you so much. it is working but shortcode not showing. i want remove p and shortcode work. how to do