Skip to content

Instantly share code, notes, and snippets.

@jeremyworboys
Forked from wesbos/is_blog.php
Created February 9, 2012 05:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyworboys/1777708 to your computer and use it in GitHub Desktop.
Save jeremyworboys/1777708 to your computer and use it in GitHub Desktop.
WordPress: is_blog()
function is_blog () {
global $post;
$posttype = get_post_type($post);
return (($posttype == 'post') && ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())));
}
Usage:
<?php if (is_blog()) { echo 'You are on a blog page'; } ?>
@jeremyworboys
Copy link
Author

Optimised function:

  • Bitwise comparisons will always return boolean; no need for ternary operator.
  • Moved post type comparison as && will short-circuit and remove the need to make || comparisons.

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