Where is the WordPress is_blog() Function

There appears to be a conditional function sorely missing from WordPress Core. We can test if we’re currently on a single post using is_singular(), or if we’re on a page using is_page() or if we’re on the home page with is_home(), and so forth. Sadly we cannot test if the current page is in fact displaying the blog with something like is_blog().

I wanted to test this condition and display a special layout if true, so I had to write my own. Turns out you’ll have to test for quite a few cases to make this foolproof. Thankfully, Wesbos already compiled such a useful function on GitHub, so I’ve forked it:

<?php
function guru_is_blog () {
global $post;
$posttype = get_post_type($post );
return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ;
}
if (guru_is_blog()) { echo 'You are on a blog page'; }
view raw is_blog.php hosted with ❤ by GitHub

Essentially it tests if we’re currently on any archive page that’s displaying regular blog posts, returning true if that’s the case. I’ve updated it with my prefix, just in case they ever DO implement it in WordPress. That way, my sites won’t break.

You can leave a comment on my original post.