Posted By

razvanstavila on 07/24/14


Tagged

wordpress editor admin


Versions (?)

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


 / Published in: PHP
 

Remove Wordpress empty paragraphs form the_content() function.

  1. add_filter('the_content', 'remove_empty_tags_recursive', 20, 1);
  2. function remove_empty_tags_recursive ($str, $repto = NULL) {
  3. $str = force_balance_tags($str);
  4. //** Return if string not given or empty.
  5. if (!is_string ($str)
  6. || trim ($str) == '')
  7. return $str;
  8.  
  9. //** Recursive empty HTML tags.
  10. return preg_replace (
  11.  
  12. //** Pattern written by Junaid Atari.
  13. '~\s?<p>(\s|&nbsp;)+</p>\s?~',
  14.  
  15. //** Replace with nothing if string empty.
  16. !is_string ($repto) ? '' : $repto,
  17.  
  18. //** Source string
  19. $str
  20. );}

Report this snippet  

You need to login to post a comment.