Check if page is a post or blog page in WordPress

I use dynamic sidebars a lot in my website design, and most of the time I have one sidebar for the blog, and one for the rest of the site. I’ve been using this function for a while and it’s pretty dang useful for how simple it is.

This is basically a function for a WordPress web developer/designer to use to check if a page is a ‘blog’ post page. It uses all of WordPress’s functions that return true if the page contains a blog-type query. If the main page query is an archive, author, category, home page, single post, tag, search results, or even the ‘post’ post type, it’ll return false. Awesome!

When I say simple, I mean it!

function is_blog() {

    global $post;

    //Post type must be 'post'.
    $post_type = get_post_type($post);

    //Check all blog-related conditional tags, as well as the current post type, 
    //to determine if we're viewing a blog page.
    return (
        ( is_home() || is_archive() || is_single() )
        && ($post_type == 'post')
    ) ? true : false ;



<?php if (is_blog()) { echo 'This is a blog page!'; } ?>

Let me know if this helps you or if you have any improvements!

Brandon has been a web designer and developer since the young age of 10 years old. He has always been devoted to graphic design and creating beautiful website designs, but he also dips his toes in the SEO, web development, and marketing fields. Brandon currently resides at the Wilmington, NC beach.
Add Comment Register

Leave a Reply

Your email address will not be published. Required fields are marked *

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