In WordPress, you often need to know what kind of page the user is currently on. This is useful when you want to change content, layout, or run specific actions depending on the page type.
WordPress provides special conditional functions:
is_front_page() – checks if the current page is the front (main) page.
is_home() – checks if it’s the posts page (the blog).
is_single() – checks if a single post is open (type post).
is_page() – checks if a regular page is open (type page).
<?php
if ( is_front_page() ) {
echo 'Front Page';
} elseif ( is_home() ) {
echo 'Blog (Posts Page)';
} elseif ( is_single() ) {
echo 'Single Post';
} elseif ( is_page() ) {
echo 'Page';
} else {
echo 'Other (Archive, Category, etc.)';
}
?>
If the user is on the main page — it shows “Front Page”.
If on the blog page — “Blog (Posts Page)”.
If a single post is open — “Single Post”.
If it’s a regular page — “Page”.
In all other cases (archives, categories, tags) — “Other”.
These checks help you:
Change the site header for the main and inner pages.
Show different widgets on posts and pages.
Add custom styles or scripts depending on the page type.
Activation and Initialization Hooks in WordPress: Where and When to Create Tables
291
How to Create a Custom Table in WordPress via functions.php: A Complete Guide to MySQL Data Types
334
HTML Select: hidden placeholder, highlight, and dynamic urgency indicator
282
How to Create a Custom Admin Menu in WordPress: A Simple Guide for Beginners
226
Customizing the WordPress Login Page: Logo, Colors, Background Image & Custom CSS
255
How to Display the Visitor’s IP Address on a Website Using PHP? 669
Adding Meta Description and Keywords in WordPress 467
How to Detect an AdBlocker on Your Site Using JavaScript 373
How to Create a Custom Table in WordPress via functions.php: A Complete Guide to MySQL Data Types 334
How to Add a Currency Widget to the WordPress Admin Dashboard 298
Leave a Reply