A conditional tag in WordPress is a function that asks a yes or no question, such as "Is this the front page?" or "Is this a single post?". It returns true or false. You use it in an if statement to decide what your theme prints.
Page tags such as is_single() need the main query, so use them in template files or on hooks like wp, template_redirect, and wp_head. If you call them at the top of functions.php, WordPress does not know the page yet.
Syntax
Syntax
A conditional tag is the test of an if statement:
WordPress
<?php if ( is_front_page() ) : ?>
<!-- code for the front page -->
<?php elseif ( is_single() ) : ?>
<!-- code for a single post -->
<?php else : ?>
<!-- code for everything else -->
<?php endif; ?>
Reference
Front Page vs Blog Posts Index
These two tags confuse many beginners. In Settings > Reading you choose what the home URL shows.
Setting
Home URL /
Blog URL /blog/
Your latest posts
is_front_page() and is_home() are both true
Not used
A static page as front page, and a Posts page
is_front_page() is true, is_home() is false
is_home() is true, is_front_page() is false
Also remember: is_single() is for posts, is_page() is for Pages, and is_singular() is for any single view. is_admin() checks the dashboard, not the user role.
Map
Function Groups at a Glance
Pick the group that matches the job, then open the guide you need.
Group
Typical job
Start here
Main query & page type
Tell the front page, blog index, single views, Pages, attachments, previews, the privacy page, and search apart.
Print a different message for the front page, a single post, and the blog index.
WordPress
<?php
if ( is_front_page() ) {
echo 'Welcome to our site!';
} elseif ( is_home() ) {
echo 'Latest blog posts';
} elseif ( is_single() ) {
echo 'You are reading a post.';
} ?>
Output
Static front page at / -> Welcome to our site!
Posts page at /blog/ -> Latest blog posts
A blog post -> You are reading a post.
The About Page -> (nothing is printed)
How It Works
Each tag returns true or false.
The first true test wins, and its message is printed.
On pages that match none of the tests, nothing is printed.
Example 2 — A sidebar rule
Hide the sidebar on Pages and show it on posts and archives.
WordPress
<?php if ( is_page() ) {
// no sidebar on Pages
} else {
get_sidebar();
} ?>
Output
On a Page (true):
(no sidebar is printed)
On a post or an archive (false):
<aside class="widget-area">...</aside>
How It Works
is_page() is true on every Page.
The if branch is empty on purpose, so nothing is printed.
The else branch calls get_sidebar() for all other pages.
Continue
Next: WordPress Conditional Functions Index
After you know the basics, open the functions index for all 34 guides.
They are functions such as is_home() and is_single() that return true or false. They tell your code which type of page the visitor is on.
Put it in the test of an if statement in a theme file. If it returns true, the code inside the braces runs.
The front page is the main page of the site. The blog posts index is the page that lists your latest posts. With latest posts as the home page they are the same. With a static front page they are different.
You may be calling it too early. Use it in a template file or on a hook such as wp or template_redirect, after WordPress has set the query.
Only inside hooks that run later, for example add_action( 'wp_head', ... ). Calling a page tag at the top of functions.php is too early.
Open the WordPress Conditional Functions index. It lists all 34 guides with short descriptions.