remove empty <p> tags from wordpress shortcodes via a php functon

Jason picture Jason · Nov 22, 2012 · Viewed 12.7k times · Source

Looking for a php function (non-jQuery or wpautop modification) approach to remove <p></p> from within wordpress.

I tried this but it does not work:

        function cleanup_shortcode_fix($content) {   
          $array = array (
            '<p>[' => '[', 
            ']</p>' => ']', 
            ']<br />' => ']',
            ']<br>' => ']'
          );
          $content = strtr($content, $array);
            return $content;
        }
        add_filter('the_content', 'cleanup_shortcode_fix');

Answer

m1r0 picture m1r0 · Jan 30, 2014

Try inserting this code in your functions.php file:

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop', 99 );
add_filter( 'the_content', 'shortcode_unautop', 100 );

enter image description here