Disable WordPress autop
Back when I first started this blog, and in turn using WordPress, the most annoying part of blogging was WordPress' auto-formatting. WordPress would strip out custom attributes, mess with my DIV and paragraph structure, and just generally raise havoc. It bugged me so much that since the inception of this blog, I've been creating the HTML for blog posts myself. That did, however, require turning off autop
-- the filter that normally formats post content. To turn off the autop
filter, simply add this PHP snippet to your theme's functions.php
file:
remove_filter('the_content', 'wpautop');
This tiny remove_filter
call could save you a word of trouble with formatting that seems out of your hands. If your WordPress blog uses multiple themes and you'd prefer to add this functionality as a plugin, you can place the following within a PHP file to be placed in the /wp-content/plugins directory
:
/* * Plugin Name: Disable autop * Author: David Walsh * Author URI: https://davidwalsh.name/ * Plugin URI: https://davidwalsh.name/disable-autop * Version: 0.1 * Description: Disable WordPress' horrible automatic formatting */ remove_filter('the_content', 'wpautop');
This would also be helpful if you would prefer to use Markdown to write posts, as you could convert the Markdown with a different plugin or by yourself within each theme file.
Now if you can figure out a way to turnoff the wordpress magic quotes function they force you to use, I’ll tell everyone how awesome you are.
Well I already do that anyway
I take it you would like my guest post to be done in HTML after all? ;)
Hahahaha. Nah, I’ll format it myself! :)
I needed something like this 2 years ago, I simply used a plug-in if I’m not mistaken. It’s a frustration indeed.
It is annoying to developers, but is quite a handy feature when your clients are entering the content.
We can not presume that everybody have the knowledge/time to format every single post by hand, so it is handy sometimes.
Intelligently inserting p tags to wrap content from the Visual tab of the editor is okay for non-technical clients. Injecting p tags into the Text (read: code) section of the editor is not. It forces technical users to stoop to kludgey workarounds like editing functions.php, or superfluous div-wrapping elements to prevent WP from p-wrapping them.
You know same thing could be done with the_excerpt and comment_text filters
Another option which worked for me…
Just open up formatting.php in the wp-includes folder, find the wpautop function (bout line 174) and comment out everything within the function, except “return $pee;” at the very end… so it should look like this:
Dude – really??? How is that easier?
And next time you update your WP install you will need to do it againl
Using your last code snippet to create a plugin caused an error regarding ‘excessive unexpected output’ or some such thing when I placed the resulting .php file in my plugins folder and activated the plugin.
I could also see your authorial information pasted at the top of my wp site while the plugin was enabled. Although wordpress warned me that it could break my site, other than the aforementioned text at the top my site continued to work fine, although it didn’t appear to disable the autoformatting.
I’m on wordpress 3.6– do you have any ideas as to why it didn’t work?
Disabling the autop feature definitely works, but when client tries to create blog posts we can’t use paragraph formatting. Anyone have an idea how to both disable the feature, but re-enable it on posts?
THANK YOU! I was in the process of writing a php function to do just this when I ran into this. You definitely saved precious time!
5 stars! Thanks David.
Wow, guys, you are far more technical than I.
I am having this problem but need to know where I can find the /wp-content/plugins directory: in my dashboard. Is it under the Plugins section? If so, can you advise exactly where?
Also, is it possible to use a particular html code at the end of each paragraph where I am having this issue?