Check if page opened is Home page in WordPress

Sometimes we want to display certain things only on certain category of pages, for example, on this website we wanted to display list of categories only on home page and for all other pages it shouldn’t display anything. To achieve this wordpress provides certain API’s to check whether we are on home page or blog page. Details of this API’s are as below,

is_front_page() – This API returns true if we are on main blog page (Settings->Reading->Your homepage displays is set to “Your latest posts”), or when Settings->Reading->Your homepage displays is set to “A static page”

is_home() – This API returns true if we are on main blog page (Settings->Reading->Your homepage displays is set to “Your latest posts”)

using this two API’s we can check on which page we are using logic something like below,

if (is_front_page() && is_home()) {

	// This page is front page and also recent posts page

} elseif (is_front_page()) {

	// This page is static home page configured using settings

} elseif (is_home()) {

	// This is Blog page listing recent posts 

} else {

	// Some other page like single page or single post page

}
Flutter Keep User Logged In - Hive... x
Flutter Keep User Logged In - Hive Database Example - Realtime login, registration example

Leave a Comment

Sign up to our newsletter!

ADB Commands Android Android Applications Android Build system Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development, Debugging and Performance Tools Development and Build Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia NDK / Middleware / HAL Operating System Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web Design and Development Website Hosting Wordpress Yocto Embedded Linux