get_tag_template

Retrieve path of tag template in current or parent template.

Description

(string) get_tag_template(); 

The hierarchy for this template looks like:

1. tag-.php 2. tag-.php 3. tag.php

An example of this is:

1. tag-wordpress.php 2. tag-3.php 3. tag.php

The template hierarchy is filterable via the hook. The template path is filterable via the hook.

Returns (string)

Full path to tag template file.


Usage

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

Defined (1)

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

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