WordPress is_tag() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Conditional tag

Definition

In WordPress, is_tag() returns true on a tag archive, the page that lists posts with one tag. A typical URL is /tag/php/.

Call it with no argument to match any tag archive. Pass an ID, a name, or a slug to match one tag. It does not tell you if the current post has a tag. For that, use has_tag().

Syntax

Use it as the test of an if statement.

WordPress
if ( is_tag() ) {
  // code for the true path
} else {
  // code for the false path
}
CallWhat it does
is_tag()True on any tag archive.
is_tag( 'php' )True on the archive of the php tag.
is_tag( array( 'php', 'css' ) )True on the archive of either tag.

For categories use is_category(). For custom taxonomies use is_tax().

Full declaration
WordPress
is_tag( int|string|int[]|string[] $tag = '' ): bool

Parameters

ParameterDescription
$tagOptional. A tag ID, name, slug, or an array of them. Default is empty, which means any tag.

Return Value

Return ValueDescription
booltrue if the main query is for a tag archive, otherwise false.

WordPress Examples

Three short theme examples. Each one shows what prints on the true path and the false path.

Example 1 — Any tag archive

Print a label above the posts.

WordPress
<?php if ( is_tag() ) {
  echo '<p>Tag: ' . single_tag_title( '', false ) . '</p>';
} ?>

How It Works

  1. is_tag() is true only on tag archives.
  2. single_tag_title() returns the name when the second argument is false.
  3. Other pages skip the code.

Example 2 — One tag

Show a note only on the php tag.

WordPress
<?php if ( is_tag( 'php' ) ) {
  echo '<p>All our PHP tutorials.</p>';
} ?>

How It Works

  1. 'php' is the tag slug.
  2. Only that archive returns true.
  3. Other tags skip the note.

Example 3 — is_tag() vs has_tag()

One checks the page. One checks the post.

WordPress
<?php
if ( is_tag( 'php' ) ) {
  echo 'On the php tag archive.';
}
if ( has_tag( 'php' ) ) {
  echo 'This post has the php tag.';
} ?>

How It Works

  1. is_tag() asks about the page type.
  2. has_tag() asks about the current post.
  3. They are different questions.

Frequently Asked Questions

It returns true or false (a bool). Use it inside an if statement.
Use has_tag( 'php' ) inside the loop. is_tag() is only for the archive page.
Yes. You can pass an ID, a name, or a slug.
is_tag() is for the built-in tag taxonomy. is_tax() is for custom taxonomies.
Conditional tags need the main query. Call them in template files or on hooks such as wp or template_redirect, not directly at the top of functions.php.

Next: is_tax()

Check if the current page is a custom taxonomy archive.

is_tax() tutorial →

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.

8 people found this page helpful