Skip to content

Instantly share code, notes, and snippets.

@ahmu83
Created March 26, 2021 03:53
Show Gist options
  • Save ahmu83/815f2e03a5e225c68e4646fea755150a to your computer and use it in GitHub Desktop.
Save ahmu83/815f2e03a5e225c68e4646fea755150a to your computer and use it in GitHub Desktop.
<?php
/**
* There is not a hard and fast rule to check if the
* current page is the blog page (the page you set in
* the settings to display blog posts). This is what the
* documentation says: "There is no conditional tag for the blog page."
*
* Read the full section here: https://codex.wordpress.org/Conditional_Tags
*
* Not sure if there is another way to achieve this!
*
*/
/**
* This function has been tested when a
* specific page has been set to display
* posts and a static page is set for the
* Homepage in "Settings > Reading: Your homepage displays"
* @return boolean
*/
function is_blog_page() {
if ( is_front_page() && is_home() ) {
// Default homepage
$is_blog_page = false;
} elseif ( is_front_page() ) {
// static homepage
$is_blog_page = false;
} elseif ( is_home() ) {
// blog page
$is_blog_page = true;
} else {
// everything else
$is_blog_page = false;
}
return $is_blog_page;
}
@ahmu83
Copy link
Author

ahmu83 commented Mar 26, 2021

There is not a hard and fast rule to check if the current page is the blog page (the page you set in the settings to display blog posts). This is what the documentation says: "There is no conditional tag for the blog page."

Read the full section here: https://codex.wordpress.org/Conditional_Tags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment