Removing P Tags in WordPress

  |   WordPress   |   5 Comments

By default WordPress will automatically inserts p tags through your content. This can seriously screw up the a layout/design and cause validation issues. There are a couple of ways to do this, depending on your technical expertise and where you would like to preventing this from taking place.

Here are the three options:

  1. Through out entire site
  2. On specific Template pages
  3. With specific page items


Through out your entire site:

Here is a quick and easy fix to stop wordpress from placing p tags anywhere within your site. You will need to open your /wp-includes/default-filters.php file and comment out the following line:
addfilter('the_content', 'wpautop');

To comment out a line in a PHP file, insert two forward slashes //  in front of the line. When your done, this is how it should look:
//addfilter('the_content', 'wpautop');

On specific template pages:

This method with allow you to stop WordPress from using theses tags on specific template pages. (i.e. page.php, home.php, index.php, or any custom template page) You will need to open the page in an editor such as the built in WordPress editor or Dreamweaver.

Locate:
<?php the_content(); ?>

and place this directly above:
<?php remove_filter (’the_content’, ‘wpautop’); ?>

it should look like this:
<?php remove_filter (‘the_content’, ‘wpautop’); ?>
<?php the_content(); ?>

With specific page items (pics, field labels, content):
This one is also fairly easy. While creating a page or post within WordPress you have the ability to type in either the “Visual” or “HTML” tab. Feel free to create the post in visual, but when you are done you will need to switch over to HTML. Locate the item you would like to remove the <p> tag on, and place <div> tags around it instead. You will need to make sure that you place div tags around each item for this to work. Below is an example:

<div>Example Item</div>

Hope this helps.  If you have a question, email it over to use via our contact form, we would be happy to help.

AUTHOR - byrd

5 Comments
  • Jake | Sep 2, 2010 at 3:48 am

    Hey Johnathon,

    Great post and it fixed my problem! BUT, I am in wordpress 3.0.1, and every time I tab between visual and HTML editor it *removes my p tags. And that messes up my layout even more than when it used to insert random p tags. So is there a way to take *both automations off? This seems like a stupid problem to have, I wish that it wouldn't mess with my HTML at all. Thanks!

  • Sofia | Sep 2, 2010 at 4:22 pm

    I've been having a problem similar to Jake's. When I switch from HTML to Visual and edit something on Visual it screws with the HTML code, which drives me crazy. WordPress also switches my < to &; or something like that. Why does this happen? Is there a fix?

    Thanks.

    Sofia

    From PDX with Love

    • Website Help | Feb 22, 2012 at 12:23 am

      Same problem as sofia, but fixed now. Thanks for the help guys.

  • Tyler Byrd | Sep 4, 2010 at 6:03 am

    Jake this is most likely do to your WYSIWYG editor attempting to clean your code. First make sure you are not forgetting to close your tags or missing an < or > sign. This is most frequently the cause for getting your tags removed.

    By default WordPress comes installed with TinyMCE. If you are still running into problems take a look at downloading a different WYSIWYG editor from WordPress's widget database. You should be able to find several that will work for you.

    Hope this helps.

  • mark | Jan 8, 2013 at 5:00 am

    THANK YOU THANK YOU THANK YOU!!!!!!
    This post saved me from so much grief! This is, single-handedly, the most helpful post in the history of the internet.