Skip to content

Instantly share code, notes, and snippets.

@jjeaton
Forked from wesbos/is_blog.php
Last active December 18, 2015 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jjeaton/5808697 to your computer and use it in GitHub Desktop.
Save jjeaton/5808697 to your computer and use it in GitHub Desktop.
WordPress' missing is_blog() function. Determines if the currently viewed page is one of the blog pages, including the blog home page, archive, category/tag, author, or single post pages.
/**
* WordPress' missing is_blog() function. Determines if the currently viewed page is
* one of the blog pages, including the blog home page, archive, category/tag, author, or single
* post pages.
*
* Doesn't include is_search(), if you only use search for the blog, then add that in or test separately
*
* @props grantnorwood
* @return bool
*/
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')
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment