Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable automatic formatting inside WordPress shortcodes

Tags:

I've seen the tutorials on creating a (raw) shortcode that leaves the code inside it untouched,

http://www.wprecipes.com/disable-wordpress-automatic-formatting-on-posts-using-a-shortcode

but unfortunately this only applies to one shortcode at a time... and because the else statement bypasses the normal filters and calls the functions directions. My other modifications to autop and texturize functions get ignored.

Is there a way to 1. match multiple shortcodes and 2. preserve my other add/remove filters to the_content?

like image 745
helgatheviking Avatar asked May 09 '11 18:05

helgatheviking


People also ask

How do I turn off auto formatting in WordPress?

Method 1. First, you'll need to paste the following code to your theme's functions. php file or a site-specific plugin. remove_filter( 'the_content' , 'wpautop' ); remove_filter( 'the_content' , 'wptexturize' );

How do I style shortcodes in WordPress?

Easy: go to Appearance > Widgets, place a WordPress Popular Posts widget on any of your sidebars, then save. Next, select the theme you want to use, save again and you'll see the exact HTML config you need to replicate the theme with your shortcode.


1 Answers

After implementing @helgatheviking's solution on multiple websites, I'm convinced that only these lines are required:

// Move wpautop filter to AFTER shortcode is processed remove_filter('the_content', 'wpautop'); add_filter('the_content', 'wpautop', 99); add_filter('the_content', 'shortcode_unautop', 100); 

Put them in your functions.php file and you're set.

like image 70
Matthew Blackford Avatar answered Oct 28 '22 22:10

Matthew Blackford