Returns boolean whether the current page is the posts page as set from the dashboard.
-
-
Save ionurboz/ab4b5582a07362a661f5b2aae2a1c4ac to your computer and use it in GitHub Desktop.
The missing is_posts_page() function of WordPress
This file contains hidden or 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 hidden or 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