WordPress Conditional Tags

Beginner
6 min read
Updated: Nov 2026
2 examples
if statements

Definition

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.

Most conditional tags go in theme files like header.php, single.php, and sidebar.php. Popular ones are is_front_page(), is_home(), is_single(), and is_page().

Use them after the query is set.

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

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; ?>

Front Page vs Blog Posts Index

These two tags confuse many beginners. In Settings > Reading you choose what the home URL shows.

SettingHome URL /Blog URL /blog/
Your latest postsis_front_page() and is_home() are both trueNot used
A static page as front page, and a Posts pageis_front_page() is true, is_home() is falseis_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.

Function Groups at a Glance

Pick the group that matches the job, then open the guide you need.

GroupTypical jobStart here
Main query & page typeTell the front page, blog index, single views, Pages, attachments, previews, the privacy page, and search apart.is_front_page(), is_home(), is_singular(), is_single(), is_page()
Archives & taxonomiesCheck category, tag, author, date, time, and post type archives.is_archive(), is_category(), is_tag(), is_tax(), is_author()
Feeds & misc queryFeeds, trackbacks, sticky posts, new days in the loop, and page templates.is_feed(), is_trackback(), is_sticky(), is_new_day(), is_page_template()
Site, user & pluginsCheck the dashboard, login state, Multisite, child themes, plugins, and widget areas.is_admin(), is_user_logged_in(), is_multisite(), is_main_site(), is_super_admin()

WordPress Examples

Two short theme examples with sample output.

Example 1 — Different text by page

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

How It Works

  1. Each tag returns true or false.
  2. The first true test wins, and its message is printed.
  3. 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();
} ?>

How It Works

  1. is_page() is true on every Page.
  2. The if branch is empty on purpose, so nothing is printed.
  3. The else branch calls get_sidebar() for all other pages.

Next: WordPress Conditional Functions Index

After you know the basics, open the functions index for all 34 guides.

Full list: WordPress Conditional Functions index (/wordpress/conditional/function).

Frequently Asked Questions

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.

Browse every conditional function

Open the functions index for simple guides with examples and FAQs.

Conditional Functions Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful