Created
March 26, 2021 03:53
-
-
Save ahmu83/815f2e03a5e225c68e4646fea755150a to your computer and use it in GitHub Desktop.
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 | |
/** | |
* 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; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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