How to Detect the Page Type in WordPress Using PHP


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.

Main Check Functions

WordPress provides special conditional functions:

  1. is_front_page() – checks if the current page is the front (main) page.

  2. is_home() – checks if it’s the posts page (the blog).

  3. is_single() – checks if a single post is open (type post).

  4. is_page() – checks if a regular page is open (type page).

Example Code

<?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.)';
}
?>

How It Works

  • 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”.

Practical Use

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.