Skip to content

Instantly share code, notes, and snippets.

@wesbos
Created September 2, 2011 19:32
Show Gist options
  • Star 66 You must be signed in to star a gist
  • Fork 23 You must be signed in to fork a gist
  • Save wesbos/1189639 to your computer and use it in GitHub Desktop.
Save wesbos/1189639 to your computer and use it in GitHub Desktop.
WordPress is_blog()
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 ;
}
Usage:
<?php if (is_blog()) { echo 'You are on a blog page'; } ?>
@andrewitomic
Copy link

Has anyone noticed that this fails when there are no posts assigned to a tag or category? $post is NULL when you visit a category/tag archive that has no posts to display. I've been using this for years and seen it on and off - i mostly use this just for page titles, which weren't showing in this case. I never looked into it because usually the categories/tags fill up with posts and it's not an issue! But clients sometimes...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment