P Tag Population Growth

I like to keep my front and back-ends looking nice, adding some padding when necessary, trimming unwanted margins and keeping my code tight! Innocent activity, right? Well, sometimes there are unintended consequences.

Maybe you know this story: you’re working on some shameless self promotion or setting up a WordPress solution for a client. You have a particular layout you’re creating and no matter what prophylactic measures you institute in the PHP, CSS or JavaScript these <p> tags just keep multiplying!

If you find yourself not knowing why your site keeps popping out automatic <p> tags, keep reading. The pesky wpautop( $text ) function is to blame and set to make mischief by default. Intended to help non-technical WordPress users write properly formatted html, the wpautop() can cause you to lose your love for coding. Unlike those cute lemmings, wpautop() is not programmed for population control.

Fortunately, there is a simple fix. Add the following lines to your beans functions.php file and you should be able to regain control of the physiological response programmed into the <p>.

01 /*
02 * Helper Functions
03 */
04 // remove all auto <p> tags from post content and excerpt
05 remove_filter( ‘the_content’, ‘wpautop’ );
06 remove_filter( ‘the_excerpt’, ‘wpautop’ );

Read more about this WordPress function in the WordPress Documentation.

Read more on Stack Overflow.

UPDATE :: Please be aware that you will need to edit your posts and pages using the text editor and manually adding your <p> tags. If you use the visual editor all P tags will be removed.

Always edit your posts using the 'Text' tab
Visual and Text edit tabs
Filed under: Tutorials

No comment yet, add your voice below!


Add a Comment

Your email address will not be published. Required fields are marked *

Comment *

Name *
Email *
Website