Disabling auto-paragraphs in WordPress

November 02, 2005

If WordPress feels that a tag you are using needs to be wrapped in a paragraph tag, it will just go ahead and do that for you no questions asked. No thank you.

I first ran into this problem when checking the site for XHTML validation after coming up with a method for producing weblog footnotes using Textpander. The XHTML would not validate: there was a closing paragraph tag without a matching opening paragraph tag. Poring over my code again and again, I knew that I wasn't doing it — WordPress was adding the rogue paragraph tag sometime subsequent to the calling of the_content(). After taking the issue up on the support forums (and finding agreement that it was indeed a bug), I noticed the problem again when I did the latest redesign, however in this instance it was adding an opening paragraph tag and not closing it, which compelled me to re-examine the issue.

After sifting through more code than I'd like to admit, I figured out a very quick and easy fix that doesn't seem to break anything else (on my site anyway). All you need to do is open the /wp-includes/default-filters.php file and comment out the following line:

addfilter('the_content', 'wpautop');

Logic would suggest that if you don't currently roll your own XHTML, then this little hack probably isn't for you, because, I'm assuming, that without this filter, posts that are typed up through the WordPress web interface are never wrapped in paragraph tags. In other words, don't comment out the above line unless you know what you're doing.

You should follow me on Twitter here