Ahmed Nuaman


builder of internets ~ developer of dreams ~ tamer of Dachshunds

Auto-disabling WordPress’s ‘wpautop’ function

WordPress has a lovely little function called ‘wpautop‘. It simply converts line spaces in the posts we write to nice paragraphs. That’s cool and all, but what if you’re writing your own paragraphs in the HTML tab when writing a post? Well there are a number of plugins out there that allow you to disable this function on a post-by-post basis, but I’m lazy, I want WordPress to disable it when there’s HTML in a post, so I wrote a little filter to handle it for me:

function handle_content($c)
{
    global $post;
   
    if ( strpos( $c, '<' ) === 0 )
    {
        remove_filter( 'the_content', 'wpautop' );
    }
   
    return $c;
}

add_filter( 'the_content', 'handle_content', 9 );

Call me silly or stupid, but this works perfectly for me. Simply it checks the very first character of a post, if it’s ‘<’ then it assumes the post is HTML based and disables the ‘wpautop’ filter.

Where have comments gone?

Good question my old fruity. I'm now sticking any post discussions on Google+. Why? Well simply it's better. WordPress's comment system isn't very elegant and nor are ones like Disqus or Livefyre, so to save hassle I've just shipped them off to a social network, like a real boss.

Search

My social skills

Latest blog posts

  • Loading posts...

Subscribe in a reader

Latest tweets

  • Loading tweets...