Remove WordPress AutoP Filter

WordPress will automatically insert <p> and </p> tags for you to separate content breaks within a post or page. If, for some reason, you want or need to remove these, you can use either of the follow code bits.

Use this code just for your theme

[sourcecode]
remove_filter(‘the_content’, ‘wpautop’);
[/sourcecode]

Use this code as a plugin

[sourcecode lang="php"]
<?php
/* Plugin Name
* Plugin URI: http://wpvibe.com
* Author: Jonathan Dingman
* Author URI: http://jonathan.vc
* Version: 1.0
* Description: Disables the <p> that is automatically inserted by WordPress
*/

remove_filter(‘the_content’, ‘wpautop’);

?>
[/sourcecode]

If you want to use the one line of code in your functions.php, it will work only for that theme. So, if you change themes, you will need to make sure to bring that code with you if you still need it. If you want to always have the filter removed, use the plugin and it will always work as long as the plugin is activated.

Get involved, Vibe with us.

3 Vibes for this post.

  1. sagive says:

    my autop isnt working.. :( i have created my own template
    and cant dind information about how to activate that.. ideas ?

  2. Chris says:

    Have been working this for a while, I have a third party plug in that needs java script to run. The main script gets called from the header.php template file and gets into each page no problem, however in order to use these third party tools you have to call a second javascript code from the page that you want it to appear in. The posts / pages always paste tags so I want to use the filter you have created here, but it pulls out all of the tags and destroys all paragraphs for all post and pages for the complete website. So I have a choice between these third party tools or recreating all the paragraphs for the entire website… not good. I love the idea of have this as a plug-in to work across multiple themes. One Better would be having the plug in create a button in TinyMCE that says… No auto for this post pls. That way you can pick and choose Per Page what you want auto tags on.

    Any Thoughts?

    • Hi Chris,

      This is what I use on one of my sites, then just add a custom field on each post/page you don’t want autop on.

      custom field name = disable_autop, value = whatever, true is fine.

      function disable_autop() {
      global $post;
      $disable_autop_var = get_post_meta($post->ID, 'disable_autop', TRUE);
      //var_dump(get_post_meta($post->ID,'disable_autop', TRUE));
      if ( !empty( $disable_autop_var ) ) {
      remove_filter('the_content', 'wpautop');
      }
      }
      add_action ('loop_start', 'disable_autop');

Trackbacks