Function and usage of is_taxonomy_hierarchical() in wordpress


Answers ( 1 )


    The is_taxonomy_hierarchical() function in WordPress is a useful tool for theme and plugin developers. It allows them to determine whether a specified taxonomy is hierarchical. Here's a detailed explanation of this function:

    Function Signature:

    is_taxonomy_hierarchical( string $taxonomy ): bool


    • Determines if a Taxonomy is Hierarchical: The main function of is_taxonomy_hierarchical() is to check if the given taxonomy (like categories, tags) is hierarchical.


    1. Initial Check: The function first checks if the specified taxonomy is a registered object in WordPress.
    2. Retrieval of Taxonomy Object: If the taxonomy exists, the function retrieves the taxonomy object.
    3. Determines Hierarchical Nature: After retrieving the taxonomy object, the function checks if the taxonomy is hierarchical. A hierarchical taxonomy means that the taxonomy allows parent-child relationships, like categories. Non-hierarchical taxonomies, like tags, do not have these relationships.
    4. Handling Non-Existent Taxonomies: If the taxonomy does not exist, the function will return false. This is the same return value for non-hierarchical taxonomies.


    • $taxonomy (string, required): The name of the taxonomy object whose hierarchical nature you want to check. Examples of taxonomy names include 'category', 'post_tag'.

    Return Value:

    • bool: The function returns a boolean (true or false).
      • true: The taxonomy is hierarchical.
      • false: The taxonomy is either non-hierarchical or does not exist.

    Sample Usage:

    if ( is_taxonomy_hierarchical( 'category' ) ) {
        echo 'Categories are hierarchical';
    } else {
        echo 'Categories are not hierarchical';

    In this example, the function checks if 'category' (a common taxonomy in WordPress) is hierarchical. Depending on the result, it outputs an appropriate message.

    Additional Notes:

    • This function is a part of WordPress's conditional tags, which are often used in themes to alter layout or functionality based on specific conditions.
    • For more comprehensive information about this and similar theme functions, it's recommended to refer to the Conditional Tags article in the WordPress Theme Developer Handbook.

    This function is particularly useful when developing themes or plugins that need to behave differently based on the structure of the taxonomies involved.

Leave an answer