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
160
How to Create a Custom Table in WordPress via functions.php: A Complete Guide to MySQL Data Types
109
HTML Select: hidden placeholder, highlight, and dynamic urgency indicator
157
How to Create a Custom Admin Menu in WordPress: A Simple Guide for Beginners
107
Customizing the WordPress Login Page: Logo, Colors, Background Image & Custom CSS
138
How to Display the Visitor’s IP Address on a Website Using PHP? 497
Adding Meta Description and Keywords in WordPress 344
How to Detect an AdBlocker on Your Site Using JavaScript 261
How to Add a Currency Widget to the WordPress Admin Dashboard 186
How to Add a “Department” Field and Restrict Category Visibility in WordPress 165
Leave a Reply