Created
December 15, 2012 23:37
-
-
Save jeremyfelt/4300938 to your computer and use it in GitHub Desktop.
is_page_for_posts() conditional
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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