15 Jan 2017

Conditional to check if a blog page or blog layout

Put the following in the themes functions.php file:


function 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 ;
}

Test it using the following conditional within your theme:

<?php if (is_blog()) { echo 'You are on a blog page'; } else { echo 'no blog'; } ?>