WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the Mailchimp plugin ( http://wordpress.org/extend/plugins/mailchimp/ )and it has a shortcode that uses output buffering to grab it's 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 concentenate a string to return instead of using output buffering, but i don't know if they'll ever bother.

share|improve this question
up vote 5 down vote accepted

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 );
share|improve this answer
    
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. – helgatheviking Jun 26 '12 at 20:48

That's 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";
chiedolabs_shortcode_wpautop_control(array('yourshortcode'));

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 https://github.com/chiedolabs/shortcode-wpautop-control

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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