Remove wpautop from shortcode content / remove whitespace in buffering

I am using the Mailchimp plugin, and it has a shortcode that uses output buffering to grab its widget’s code and spit it out in the content.

However, the widget code has plenty of white space, so the_content filters are throwing useless linebreaks (like after hidden inputs) and empty p tags everywhere… rendering it unusable. I am removing the shortcode to add my own, but I’m not sure what to do to prevent the WordPress wpautop filter from going crazy. My initial thought was to strip out the whitespaces between HTML tags, but I don’t know how to go about doing that.

Ideally, the plugin would concatenate a string to return instead of using output buffering, but I don’t know if they’ll ever bother.

3 s
3

You do not need a plugin to do this. Just add 3 lines of code to the end of the functions.php file in your active theme:

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

Leave a Comment