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”)

Related :   How to Integrate Google reCAPTCHA into website forms to avoid spam

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

}

lynxbee_ezoic

Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google FeedBurner )

   


Leave a Comment

Android Android Build system Android Commands Android Java Applications 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 & Build Development, Debugging and Performance Tools 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 Audio, Video, Images NDK / Middleware / HAL OS 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 / Bitbake / Openembedded