is_tax

Home » Functions » is_tax

The is_tax function in WordPress is used to check if the current page is a taxonomy archive page. A taxonomy is a way to group posts together based on their characteristics, such as categories or tags.

This function can be helpful when you want to perform certain actions or display specific content only on taxonomy archive pages. For example, you may want to show a specific banner or sidebar widget only on the category archive pages.

The is_tax function takes one parameter, which is the taxonomy name or an array of taxonomy names. If the current page matches any of the specified taxonomies, the function will return true. Otherwise, it will return false.

Here’s an example usage code:

if (is_tax('category')) {
   // Display specific content or execute actions for category archive pages
   echo 'This is a category archive page.';
} elseif (is_tax(array('tag', 'genre'))) {
   // Display specific content or execute actions for tag or genre archive pages
   echo 'This is a tag or genre archive page.';
} else {
   // Display default content
   echo 'This is not a taxonomy archive page.';
}

In this example, we are using the is_tax function to check if the current page is a category archive page. If it is, we display a specific message. Then, we use the is_tax function again to check if the current page is a tag or genre archive page, and display a different message for those cases. Finally, if none of the conditions are met, we display a default message indicating that it’s not a taxonomy archive page.

Learn More on WordPress.org

WordPress snippets using the is_tax function

Register an account to save your snippets or go Pro to get more features.