Return to Snippet

Revision: 66956
at July 24, 2014 23:34 by razvanstavila


Initial Code
add_filter('the_content', 'remove_empty_tags_recursive', 20, 1);
function remove_empty_tags_recursive ($str, $repto = NULL) {
         $str = force_balance_tags($str);
         //** Return if string not given or empty.
         if (!is_string ($str)
         || trim ($str) == '')
        return $str;

        //** Recursive empty HTML tags.
       return preg_replace (

              //** Pattern written by Junaid Atari.
              '~\s?<p>(\s|&nbsp;)+</p>\s?~',

             //** Replace with nothing if string empty.
             !is_string ($repto) ? '' : $repto,

            //** Source string
           $str
);}

Initial URL

                                

Initial Description
Remove Wordpress empty paragraphs form the_content() function.

Initial Title
Wordpress - Remove Empty paragraph tags with (nbsp)  from the_content()

Initial Tags
wordpress

Initial Language
PHP