In WordPress, is_tax() returns true on the archive of a custom taxonomy, for example a genre taxonomy for books.
It does not match categories or tags. Those have their own functions, is_category() and is_tag(). Pass a taxonomy name, and optionally a term, to be more exact.
Syntax
Use it as the test of an if statement.
WordPress
if ( is_tax() ) {
// code for the true path
} else {
// code for the false path
}
Call
What it does
is_tax()
True on any custom taxonomy archive.
is_tax( 'genre' )
True on any archive of the genre taxonomy.
is_tax( 'genre', 'fiction' )
True on the fiction term of the genre taxonomy.
For built-in taxonomies use is_category() and is_tag().
On /genre/fiction/ (true):
<h1>Fiction</h1>
On a category archive (false):
(nothing is printed)
How It Works
is_tax() is true on custom taxonomy archives.
single_term_title() returns the term name.
Categories and tags return false.
Example 2 — One taxonomy
Show a note on every genre archive.
WordPress
<?php if ( is_tax( 'genre' ) ) {
echo '<p>Browse books by genre.</p>';
} ?>
Output
On /genre/fiction/ or /genre/history/ (true):
<p>Browse books by genre.</p>
On other archives (false):
(nothing is printed)
How It Works
'genre' is the taxonomy name.
Every term of that taxonomy returns true.
Other taxonomies skip the note.
Example 3 — One term
Match a taxonomy and one term.
WordPress
<?php if ( is_tax( 'genre', 'fiction' ) ) {
echo '<p>Our best stories.</p>';
} ?>
Output
On /genre/fiction/ (true):
<p>Our best stories.</p>
On /genre/history/ (false):
(nothing is printed)
How It Works
The first argument is the taxonomy.
The second argument is the term slug.
Only that one term returns true.
Frequently Asked Questions
It returns true or false (a bool). Use it inside an if statement.
No. Categories use is_category() and tags use is_tag().
Use register_taxonomy() in your theme or plugin.
Use is_category() || is_tag() || is_tax(). Or use is_archive() for every archive type.
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.