Using WordPress ‘is_tax()’ PHP function

The is_tax() WordPress PHP function determines whether the query is for an existing custom taxonomy archive page.

Usage

is_tax( $taxonomy, $term )

Custom Example:

Input: is_tax( 'genre', 'comedy' )

Output: true if the query is for the ‘comedy’ term in the ‘genre’ taxonomy, false otherwise.

Parameters

  • $taxonomy (string|string[] – Optional): Taxonomy slug or array of slugs to check against. Default: ''
  • $term (int|string|int[]|string[] – Optional): Term ID, name, slug, or array of such to check against. Default: ''

More information

See WordPress Developer Resources: is_tax()

Examples

Check if any custom taxonomy archive page is being displayed

if ( is_tax() ) {
    // Code to execute if any custom taxonomy archive page is being displayed
}

Check if the ‘channel’ taxonomy archive page is being displayed

if ( is_tax( 'channel' ) ) {
    // Code to execute if the 'channel' taxonomy archive page is being displayed
}

Check if the ‘channel’ taxonomy archive page with term ‘BBC1’ is being displayed

if ( is_tax( 'channel', 'BBC1' ) ) {
    // Code to execute if the 'channel' taxonomy archive page with term 'BBC1' is being displayed
}

Check if the archive page for either the ‘channel’ or ‘broadcaster’ taxonomies is being displayed

if ( is_tax( array( 'channel', 'broadcaster' ) ) ) {
    // Code to execute if either the 'channel' or 'broadcaster' taxonomy archive page is being displayed
}

Check if the ‘custom_taxonomy’ archive page with a specific term object is being displayed

if ( is_tax( 'custom_taxonomy', $taxonomy_term_object ) ) {
    // Code to execute if the 'custom_taxonomy' archive page with the specific term object is being displayed
}