Skip to content

Instantly share code, notes, and snippets.

@ionurboz
Forked from abelcallejo/README.md
Created March 4, 2024 11:34
Show Gist options
  • Save ionurboz/ab4b5582a07362a661f5b2aae2a1c4ac to your computer and use it in GitHub Desktop.
Save ionurboz/ab4b5582a07362a661f5b2aae2a1c4ac to your computer and use it in GitHub Desktop.
The missing is_posts_page() function of WordPress

is_posts_page()

Returns boolean whether the current page is the posts page as set from the dashboard.

<?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;
}
}
?>
<?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