Stopping WordPress from Auto Formatting

Have you ever worked real hard on a post, saved it, and then noticed that WordPress added p tags to areas you did not want them! When you went back to your article, then the p tags are all removed! That is the problem with the visual editor that comes with WordPress and WordPress itself. The visual editor will not save the p tags in the post, but WordPress has a filter that automatically adds them to posts.

You have to understand, WordPress was designed to make blogging easy for those that know absolutely nothing about HTML. They just create their posts with the visual editor and publish without ever thinking about the underlying HTML code. But, for those that are running websites that are more technical in nature, it can be very frustrating. But, it does not need to be. WordPress is a very flexible platform that allows you to change the behaviour quite easily. Today, we are going to stop all the automatic formatting. Be careful, when this fix is in place, all your p tags will not be automatically added any more! You might want to fix all of the older posts first with the HTML editor, then install this fix.

First, create a ‘WPPHP’ script with the name ‘remove_wpauto’. Then add the following code:

remove_filter('the_content', 'wpautop');
remove_filter('the_excerpt', 'wpautop');

This code simply removes the ‘wpautop’ function from two filters: ‘the_content’, and ‘the_excerpt’. It does this by using the WordPress function ‘remove_filter()’.

Now, we need to run this code at a proper time. Now, create a WordPress Action called ‘wp_loaded’ and place this line inside:

[CodeInsert lang='WPPHP' name='remove_wpauto' param='']

That is all. Now, WordPress will never modify your code again! This helps out on my website a whole lot! I hope it is helpful to you too.

comments powered by Disqus