Disable Automatic Paragraphs & Line-breaks In WordPress Posts

By .     What do you think of this article?

I’ve mentioned previously that I prefer handwriting code instead of having it done automatically. When I code manually, I get the functionality and presentation exactly the way I want. One such feature in WordPress (I’ve disabled so many) counters my preference by doing something automatically. What I’m referring to is WordPress automatically adding paragraph (<p>) tags and line-breaks (<br />) to the final markup of posts. This feature is provided by the WpAutoP function.

If I press the Return/Enter key once while writing a post, a line-break will automatically be added. If I press it twice, WordPress thinks I’m creating a new paragraph, so it adds a closing tag and opens a new one. (They don’t show up in the editor, but they’ll be there when the post is rendered to the reader.) Both accounts can be certainly wrong. I write my syntax so that it’s easy for me to read from the source, and that means leaving blank lines where I feel appropriate. What may be a blank line in the source doesn’t equate to a desired new line or paragraph in the presentation (what you see when you load the webpage).

What makes it silly is that I always use the HTML editor when publishing a post, never the Visual/WYSIWYG editor. If I’m posting something from the HTML editor, any syntax that appears in the final markup should be input in the HTML editor – no automatic line-breaks or paragraphs. Plus, I code line breaks in HTML 5 rather than xHTML.

Fortunately, there is an easy way to disable this automatic function. Open up your theme’s functions.php file or the Functions.php Plugin you may have made and add in the following:

  1. /**
  2.  * Disable auto paragraphs and line-break
  3.  * http://www.computertechtips.net/191/disable-automatic-paragraphs-and-line-breaks-in-wordpress-posts/
  4.  */
  5. remove_filter('the_content', 'wpautop');

What this means, however, is that you need to go through all your previous posts in which you relied on this automatic function and manually add your own line-breaks and paragraphs in the post. Otherwise, some of your content will seem like a big block of text rather than well spaced and presented as you intended. It’s a small price to pay for the long-run, in my opinion.

Depending on how your theme is setup and how you’re displaying post excerpts, you may also want to add this filter as well. It isn’t needed for the present Computer Tech Tips theme. remove_filter('the_excerpt', 'wpautop');

Posted in: Web Development



is the site owner of Computer Tech Tips and is passionate about computer technology, particularly Windows-based software, malware removal, and web development. He enjoys helping people troubleshoot computer problems and providing technical support to family, friends, and people around the net. Xps wrote 79 article(s) for Computer Tech Tips.


 Subscribe to comments: this article | all articles
Comments are automatically closed to prevent SPAM.