Stop WordPress from adding <p> tags in your page content

Want to stop WordPress from adding paragraph tags to your content? Here’s a quick guide to help you.

Why stop <p> tags?

WordPress is easy to use, but sometimes it adds paragraph tags when you don’t want them.

This can mess up your page layout.

How to fix it

To stop WordPress from adding <p> tags, add the following code snippet to your theme’s functions.php file.

Removing <p> tags on pages only:

// Stop WP from adding <p> tags on pages
function disable_wp_auto_p( $content ) {
  if ( is_singular( 'page' ) ) {
    remove_filter( 'the_content', 'wpautop' );
    remove_filter( 'the_excerpt', 'wpautop' );
  }
  return $content;
}
add_filter( 'the_content', 'disable_wp_auto_p', 0 );

Remove <p> tags on pages, posts, and other post types:

// Stop WP from adding <p> tags on all post types
function disable_wp_auto_p( $content ) {
  remove_filter( 'the_content', 'wpautop' );
  remove_filter( 'the_excerpt', 'wpautop' );
  return $content;
}
add_filter( 'the_content', 'disable_wp_auto_p', 0 );