WordPress Editor – disabling wpautop()

More WordPress tips and tweaks

More WordPress tips and tweaks

I always use the HTML View when using the WordPress Post/Page Editor, because I like to have as much control as possible over the HTML markup I incorporate into my posts, and have never been comfortable using the Visual View. However, even in HTML View, WordPress automatically deals with <p> and <br /> tags, which can be frustrating sometimes when it either seems to ignore the spacing you have inserted between lines of text or images in your post, or adds some where you don’t want them! Luckily, it is a very easy job to disable this behaviour.

wpautop()

The WordPress wpautop() function handles this aspect of Post/Page formatting. This function filters the_content() and the_excerpt() and, because it is a WordPress Filter, it’s very easy to disable it.

Before you read the next section, just bear in mind what disabling wpautop() means. Firstly, you will need to manually add <p> and <br /> tags whenever you write a Post or Page from now on and, secondly and more importantly, you will need to go back into every existing Post and Page and manually add the <p> and <br /> tags.

This is because the <p> and <br /> tags in your Posts and Pages are NOT saved in the database. The <p> and <br /> tags you currently see, when viewing Posts and Pages in the browser, are added by the wpautop() function between database and browser. (That’s why it is called a Filter, by the way. It “filters” whatever is passed through it – in this case the_content() and the_excerpt()).

So, please bear this in mind before proceeding…

Disabling wpautop()

To disable wpautop(), just add this code to your theme’s functions.php file:

//disable wpautop filter
remove_filter ('the_content',  'wpautop');

That’s it! It really is that simple…

Don’t forget to add the <p> and <br /> tags in HTML View in the Editor when writing Posts and Pages!

And finally…

Observant visitors will notice that some of my older posts look rather poorly formatted at the moment. That’s because having disabled wpautop() last week, I haven’t yet got around to re-editing all my Posts!

Comments

  1. Hello,
    i love the way you explain your tutorials
    thanks for the codes and knowledge u share it with us.
    YOU ARE GENIUS.

  2. Hi,

    Just writing a note to let you know that I released a plugin which lets you disable the wpautop filter with a twist.

Trackbacks

Leave a Comment

*


three + = 9

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>