Ankhou Graphic Design

Web development, graphic design, and photography by Ian Houghton, based in Revelstoke, BC.

stop WordPress inserting paragraph tags

4 Comments | posted 1/08/09

I came across an IE display issue with my portfolio recently where the divs of the individual projects were ‘staircased’ down the page, with a whitespace break of about half the height of the div between the top of the previous project and the top of the next one. It was irritating, and I couldn’t figure out what was causing it until I examined the source code that the browsers were generating and discovered WordPress was automatically inserting <p> tags around certain other tags (even in HTML view in the visual editor!), which IE was interpreting as whitespace.

A quick bit of googling came up with a couple of different solutions which I’ve listed below.

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');

From justinblanton.com.

(Note: to comment out a line in a PHP file, insert two forward slashes in front of the line.)

By default, WordPress automatically inserts paragraph tags all over the place when displaying ‘the_content’ – this often gets in the way when you’re trying to space out your text, and also creates validation issues (inserting implicit <p>). If you want to strip the automatically inserted paragraph tags from your content, simply insert this line in your template file above ‘the_content’ tag:

<?php remove_filter (’the_content’, ‘wpautop’); ?>

From thewebsiteprofessionals.com.

4 responses to “stop WordPress inserting paragraph tags”

  1. You are amazing! This was exactly what I was looking for. Thanks a million for your help!

    Cheers!

  2. No problem Ryan, glad it helped you out.

  3. Unfortunately it strips even the P tags that I add….very weird

  4. Finally! Thanks. It helped knowing which file to edit. You were the only one that made it clear and the p is gone. Thanks again.

leave a reply

« Newer: | Older: »