Support

Account

Home Forums Front-end Issues Hide empty P tags generated by WYSIWYG Reply To: Hide empty P tags generated by WYSIWYG

  • Thanks John – however, a detailed solution came through (which I think you were pointing me towards) from James on support@advancedcustomfields.com 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!