get_taxonomy_template

Retrieve path of custom taxonomy term template in current or parent template.

Description

(string) get_taxonomy_template(); 

The hierarchy for this template looks like:

1. taxonomy--.php 2. taxonomy-.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 hook. The template path is filterable via the hook.

Returns (string)

Full path to custom taxonomy term template file.


Usage

  1. if ( !function_exists( 'get_taxonomy_template' ) ) { 
  2. require_once ABSPATH . WPINC . '/template.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = get_taxonomy_template(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/template.php  
  1. function get_taxonomy_template() { 
  2. $term = get_queried_object(); 
  3.  
  4. $templates = array(); 
  5.  
  6. if ( ! empty( $term->slug ) ) { 
  7. $taxonomy = $term->taxonomy; 
  8.  
  9. $slug_decoded = urldecode( $term->slug ); 
  10. if ( $slug_decoded !== $term->slug ) { 
  11. $templates[] = "taxonomy-$taxonomy-{$slug_decoded}.php"; 
  12.  
  13. $templates[] = "taxonomy-$taxonomy-{$term->slug}.php"; 
  14. $templates[] = "taxonomy-$taxonomy.php"; 
  15. $templates[] = 'taxonomy.php'; 
  16.  
  17. return get_query_template( 'taxonomy', $templates );