get_taxonomy_template

The timeline below displays how wordpress function get_taxonomy_template has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Retrieves path of custom taxonomy term template in current or parent template.
 *
 * The hierarchy for this template looks like:
 *
 * 1. taxonomy-{taxonomy_slug}-{term_slug}.php
 * 2. taxonomy-{taxonomy_slug}.php
 * 3. taxonomy.php
 *
 * An example of this is:
 *
 * 1. taxonomy-location-texas.php
 * 2. taxonomy-location.php
 * 3. taxonomy.php
 *
 * The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'}
 * and {@see '$type_template'} dynamic hooks, where `$type` is 'taxonomy'.
 *
 * @since 2.5.0
 * @since 4.7.0 The decoded form of `taxonomy-{taxonomy_slug}-{term_slug}.php` was added to the top of the
 *              template hierarchy when the term slug contains multibyte characters.
 *
 * @see get_query_template()
 *
 * @return string Full path to custom taxonomy term template file.
 */
function get_taxonomy_template()
{
    $term = get_queried_object();
    $templates = array();
    if (!empty($term->slug)) {
        $taxonomy = $term->taxonomy;
        $slug_decoded = urldecode($term->slug);
        if ($slug_decoded !== $term->slug) {
            $templates[] = "taxonomy-{$taxonomy}-{$slug_decoded}.php";
        }
        $templates[] = "taxonomy-{$taxonomy}-{$term->slug}.php";
        $templates[] = "taxonomy-{$taxonomy}.php";
    }
    $templates[] = 'taxonomy.php';
    return get_query_template('taxonomy', $templates);
}

WordPress Version: 4.9

/**
 * Retrieve path of custom taxonomy term template in current or parent template.
 *
 * The hierarchy for this template looks like:
 *
 * 1. taxonomy-{taxonomy_slug}-{term_slug}.php
 * 2. taxonomy-{taxonomy_slug}.php
 * 3. taxonomy.php
 *
 * An example of this is:
 *
 * 1. taxonomy-location-texas.php
 * 2. taxonomy-location.php
 * 3. taxonomy.php
 *
 * The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'}
 * and {@see '$type_template'} dynamic hooks, where `$type` is 'taxonomy'.
 *
 * @since 2.5.0
 * @since 4.7.0 The decoded form of `taxonomy-{taxonomy_slug}-{term_slug}.php` was added to the top of the
 *              template hierarchy when the term slug contains multibyte characters.
 *
 * @see get_query_template()
 *
 * @return string Full path to custom taxonomy term template file.
 */
function get_taxonomy_template()
{
    $term = get_queried_object();
    $templates = array();
    if (!empty($term->slug)) {
        $taxonomy = $term->taxonomy;
        $slug_decoded = urldecode($term->slug);
        if ($slug_decoded !== $term->slug) {
            $templates[] = "taxonomy-{$taxonomy}-{$slug_decoded}.php";
        }
        $templates[] = "taxonomy-{$taxonomy}-{$term->slug}.php";
        $templates[] = "taxonomy-{$taxonomy}.php";
    }
    $templates[] = 'taxonomy.php';
    return get_query_template('taxonomy', $templates);
}

WordPress Version: 4.7

/**
 * Retrieve path of custom taxonomy term template in current or parent template.
 *
 * The hierarchy for this template looks like:
 *
 * 1. taxonomy-{taxonomy_slug}-{term_slug}.php
 * 2. taxonomy-{taxonomy_slug}.php
 * 3. taxonomy.php
 *
 * An example of this is:
 *
 * 1. taxonomy-location-texas.php
 * 2. taxonomy-location.php
 * 3. taxonomy.php
 *
 * The template hierarchy is filterable via the {@see 'taxonomy_template_hierarchy'} hook.
 * The template path is filterable via the {@see 'taxonomy_template'} hook.
 *
 * @since 2.5.0
 * @since 4.7.0 The decoded form of `taxonomy-{taxonomy_slug}-{term_slug}.php` was added to the top of the
 *              template hierarchy when the term slug contains multibyte characters.
 *
 * @see get_query_template()
 *
 * @return string Full path to custom taxonomy term template file.
 */
function get_taxonomy_template()
{
    $term = get_queried_object();
    $templates = array();
    if (!empty($term->slug)) {
        $taxonomy = $term->taxonomy;
        $slug_decoded = urldecode($term->slug);
        if ($slug_decoded !== $term->slug) {
            $templates[] = "taxonomy-{$taxonomy}-{$slug_decoded}.php";
        }
        $templates[] = "taxonomy-{$taxonomy}-{$term->slug}.php";
        $templates[] = "taxonomy-{$taxonomy}.php";
    }
    $templates[] = 'taxonomy.php';
    return get_query_template('taxonomy', $templates);
}

WordPress Version: 4.3

/**
 * Retrieve path of taxonomy template in current or parent template.
 *
 * Retrieves the taxonomy and term, if term is available. The template is
 * prepended with 'taxonomy-' and followed by both the taxonomy string and
 * the taxonomy string followed by a dash and then followed by the term.
 *
 * The taxonomy and term template is checked and used first, if it exists.
 * Second, just the taxonomy template is checked, and then finally, taxonomy.php
 * template is used. If none of the files exist, then it will fall back on to
 * index.php.
 *
 * The template path is filterable via the dynamic {@see '$type_template'} hook,
 * e.g. 'taxonomy_template'.
 *
 * @since 2.5.0
 *
 * @see get_query_template()
 *
 * @return string Full path to taxonomy template file.
 */
function get_taxonomy_template()
{
    $term = get_queried_object();
    $templates = array();
    if (!empty($term->slug)) {
        $taxonomy = $term->taxonomy;
        $templates[] = "taxonomy-{$taxonomy}-{$term->slug}.php";
        $templates[] = "taxonomy-{$taxonomy}.php";
    }
    $templates[] = 'taxonomy.php';
    return get_query_template('taxonomy', $templates);
}

WordPress Version: 3.9

/**
 * Retrieve path of taxonomy template in current or parent template.
 *
 * Retrieves the taxonomy and term, if term is available. The template is
 * prepended with 'taxonomy-' and followed by both the taxonomy string and
 * the taxonomy string followed by a dash and then followed by the term.
 *
 * The taxonomy and term template is checked and used first, if it exists.
 * Second, just the taxonomy template is checked, and then finally, taxonomy.php
 * template is used. If none of the files exist, then it will fall back on to
 * index.php.
 *
 * The template path is filterable via the 'taxonomy_template' hook.
 *
 * @since 2.5.0
 *
 * @see get_query_template()
 *
 * @return string Full path to taxonomy template file.
 */
function get_taxonomy_template()
{
    $term = get_queried_object();
    $templates = array();
    if (!empty($term->slug)) {
        $taxonomy = $term->taxonomy;
        $templates[] = "taxonomy-{$taxonomy}-{$term->slug}.php";
        $templates[] = "taxonomy-{$taxonomy}.php";
    }
    $templates[] = 'taxonomy.php';
    return get_query_template('taxonomy', $templates);
}

WordPress Version: 3.7

/**
 * Retrieve path of taxonomy template in current or parent template.
 *
 * Retrieves the taxonomy and term, if term is available. The template is
 * prepended with 'taxonomy-' and followed by both the taxonomy string and
 * the taxonomy string followed by a dash and then followed by the term.
 *
 * The taxonomy and term template is checked and used first, if it exists.
 * Second, just the taxonomy template is checked, and then finally, taxonomy.php
 * template is used. If none of the files exist, then it will fall back on to
 * index.php.
 *
 * @since 2.5.0
 * @uses apply_filters() Calls 'taxonomy_template' filter on found path.
 *
 * @return string
 */
function get_taxonomy_template()
{
    $term = get_queried_object();
    $templates = array();
    if (!empty($term->slug)) {
        $taxonomy = $term->taxonomy;
        $templates[] = "taxonomy-{$taxonomy}-{$term->slug}.php";
        $templates[] = "taxonomy-{$taxonomy}.php";
    }
    $templates[] = 'taxonomy.php';
    return get_query_template('taxonomy', $templates);
}