Skip to content

Instantly share code, notes, and snippets.

@jeremyfelt
Created December 15, 2012 23:37
Show Gist options
  • Save jeremyfelt/4300938 to your computer and use it in GitHub Desktop.
Save jeremyfelt/4300938 to your computer and use it in GitHub Desktop.
is_page_for_posts() conditional
<?php
/**
* If you have a static page set for posts and want to conditionally load
* something for it, things seem tricky.
*
* is_post_type_archive( 'post' ) will return false, because it thinks it's a page
* is_home() will return true on the 'blog' page, but false on category archives
* is_archive() will return true as expected, but also returns true for other post types
*
* Combining them allows for a proper conditional. I think.
*
**/
function is_page_for_posts() {
return ( is_home() || ( is_archive() && ! is_post_type_archive() ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment