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 Answers 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 );
  • i don't know what exactly i was smoking the other day, but i'm not even experiencing this problem today. thanks for the answer though. i think it causes some trouble as HTML comments seem to get wrapped in p tags. Jun 26, 2012 at 20:48

shea's answer is a nice solution, but it turns off autop for all shortcodes which may not be desired.

I wrote a script that allows you to run the following:

include "shortcode-wpautop-control.php";

It allows you to turn off wpautop for specific shortcodes instead of all of them.

Once again, I wrote the script. I don't mean to self promote, but as I update it in the future, I will update it on GitHub, so it makes no sense to post the code here.

You can see the script at Shortcode wp-autop control.

  • Are you actively maintaining this code? It looks useful but I don't wanna invest any time into something that isn't being actively maintained. Mar 29, 2016 at 6:49
  • Good question. I'd say I'm not actively maintaining it since not many people have been using it since I launched it. I have WordPress plugins using it that depend on it though so if there are Issues placed on GitHub, I will fix them.
    – Chiedo
    Mar 30, 2016 at 12:44
  • So I'm reactively maintaining the code as opposed to actively.
    – Chiedo
    Mar 30, 2016 at 12:44
  • Ok fair enough. Mar 31, 2016 at 13:01
  • I would use this, but I need wpautop for parts of my shortcode contents, just not in between the shortcodes. Example: [row] \n [cell] \n content \n [/cell] [/row] should become <row><cell><br>content<br></cell></row> Apr 14, 2016 at 22:54

There is a WordPress function available that does this job nicely. There isn't any need to use a custom function or a plugin to do this.

Just use the shortcode_unautop($pee) function to remove wpautop from shortcode content. Here $pee is the required string.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.