WordPress Tips by Ideas and Pixels

Anyone who has worked with WordPress knows how bad the automatic formatting can when you are creating your pages or posts. This will work when the WordPress plugin, PS Disable Auto Formatting, will not.

Thankfully, after hours of testing and looking for helpful advice we stumbled on the best solution; to our amazement it is just a bit of short code.

This short code will disable only the selected portions of text that you do not wish WordPress to auto format, solving this annoying WordPress auto formatting problem!

Place this code within your functions.php file using the standard PHP Layout:

$new_content = ''; $pattern_full = '{(\[raw\].*?\[/raw\])}is'; $pattern_contents = '{\[raw\](.*?)\[/raw\]}is'; $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($pieces as $piece) { if (preg_match($pattern_contents, $piece, $matches)) { $new_content .= $matches[1]; } else { $new_content .= wptexturize(wpautop($piece)); } } return $new_content; } remove_filter('the_content', 'wpautop'); remove_filter('the_content', 'wptexturize'); add_filter('the_content', 'my_formatter', 99); ?>

Then all you have to do within your WordPress, posts or pages, is block of the sections of text that you do not wish to have the WordPress auto format, using [RAW] tags: [raw]Place the RAW TAGS around the text you do not wish to have auto formatted, as it is done here![/raw]

Many thanks to TheBinaryPenguin for posting this solution!

About The Author: Matt has a very extensive experience of print and web design. He is an effective team player known for creativity, flexibility, distributing skills, managing, working with others and producing high quality, effective works of art within a deadline.

  • Kurt

    Matt: Thanks for this bit of code. The editor was adding break tags and p tags to my shortcodes. It was driving me nuts. Your code does the trick! Thanks!

  • http://www.facebook.com/valvanomatt Matt Valvano

    Kurt, your absolute welcome! This seriously took me forever to figure out for one of my clients when we converted his CSS site to WordPress. We are planning on posting more issues will solutions that we run into as well. If you find anything else that you might be having with WordPress, just let us know and we will try to help out with these issues, as well.

  • Pingback: 10 Awesome Shortcodes For Your WordPress Blog()

  • Pingback: 10 Awesome Shortcodes For Your WordPress Blog | Wordpress Themes()

  • Pingback: 10 Awesome Shortcodes For Your WordPress Blog | SNS Online()

  • Pingback: A Free wordpress newsletter » 10 Awesome Shortcodes For Your WordPress Blog()

  • Pingback: wp-coder.net » 10 Awesome Shortcodes For Your WordPress Blog()

  • Pingback: 10 Awesome Shortcodes For Your WordPress Blog()

  • Pingback: Wodpress – Disable Autoformatting in a Post or Page « Codewars.net()

  • Bash

    thank god this worked. nothing else i tried would disable wpautop. Cheers 

    • mrgingrich

      Me either, Bash!

  • Brennan Allen

    When I tried this, it created a fatal error at the last } before the functions.. any ideas?

    • http://www.facebook.com/valvanomatt Matt Valvano

      What version of WordPress are you using? I will look into this further with you.

      • Suhaib M. Siddiqi

        I had same issue. I inserted the code before ?> I removed the last } after which is after
        return $new_content; Then, it worked. It could a theme issue. I am using MySiteMyWay Elegance theme.

  • Pingback: Understanding and Using WordPress Shortcodes | Search Engine People | Toronto()

  • Martin

    What is meant by “using the standard PHP layout”?

  • kaNTRi

    content not rendering correctly if content already contains short code …

    [raw]Place the RAW TAGS[myshortcoe] around the text you do not wish to have auto formatted[myshortcoe], as it is done here![/raw]

    in this above case this function not working as desired

    • http://www.facebook.com/valvanomatt Matt Valvano


      Yes I noticed this too. I ended up creating a separate php document (in my case for the contact form) and called it this way. However you cannot use the WordPress short code and have to call on the long format.

      I will update this post once I look into this a little more!


  • Diane Chan

    Help, it’s not working for me. : ( Running WP3.4.1, inserted this code into my child theme’s functions file, but got the white page when I tried to refresh the admin window. My functions file has other code in it. Whether I pasted the code inbetween other functions or at the end, same problem. Left off the ?&gt, still a white screen. Eliminated spaces, still a white screen. See http://pastebin.com/dz6uDP6V.

    • http://www.facebook.com/valvanomatt Matt Valvano


      This code can be stand alone and outside of that function’s php string. Try http://pastebin.com/Wyx0A8Ck

      Just paste this at the very bottom and outside of your ?> within your function’s php.

      I think it was due to the conflict with the rest of the code in your functions php. This should work and if it doesn’t let me know!

  • sapiringo

    thanks Matt, I got it running and working… Saved me! I was freaking out with thos p tags… just to share with others, I couldnt make the shortcode [raw][/raw] work if I wrote it manually, i had to click on the button on the bar in Text mode…and I renamed the function to whatever i wanted when I pasted the code on my functions.php hope it helps, thanks!

    • http://www.facebook.com/valvanomatt Matt Valvano

      Your welcome! Thanks for the heads up about the tags not working how I currently have it. I will update this post because I wrote it about 3 or 4 WordPress updates ago. Just need to finish our new blog layout first.. sigh (Ha Ha!).

      This is probably the issue Diane, below, was having!

  • Suhaib M. Siddiqi

    Matt thanks a lot. I have a plugin which required inserting a shortcode in a page via Peter’s Include plugin. The WP was driving me nuts for 3 days by inserting and all over on this particular page. I tried old solution of adding remove_filter(‘the_content’, ‘wpautop’); but no help. I also tried WP plugins to disable autop without success. Until, Google search brought me to your page. It worked perfect.

    • http://www.facebook.com/valvanomatt Matt Valvano

      Your welcome Suhaib! This was a major problem for one of our client’s projects and I am glad I was able to find the answer too.

  • infoturk

    Worked like a charm. Great post. Thanks for sharing.