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:

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.

Jay is founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or drawing on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.

You can leave a comment on my original post.