Returns boolean whether the current page is the posts page as set from the dashboard.
Created
December 1, 2019 20:48
-
-
Save abelcallejo/88a0769d40b280fb1b2830c2de38122f to your computer and use it in GitHub Desktop.
The missing is_posts_page() function of WordPress
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( !function_exists('is_posts_page') ){ | |
function is_posts_page(){ | |
$page_for_posts = intval( get_option( 'page_for_posts' ) ); | |
$current_page = get_queried_object_id(); | |
if( $page_for_posts === $current_page ){ | |
return true; | |
} | |
return false; | |
} | |
} | |
?> |
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( is_front_page() ){ | |
// codes for rendering the home page | |
// see https://developer.wordpress.org/themes/basics/template-files/ | |
} elseif ( is_posts_page() ) { | |
// codes for rendering the loop | |
// see https://developer.wordpress.org/themes/basics/the-loop/ | |
} | |
// see https://wphierarchy.com/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment