WordPress Version: 4.3
/**
* Retrieve path of tag template in current or parent template.
*
* Works by first retrieving the current tag name, for example 'tag-wordpress.php',
* and then trying tag ID, for example 'tag-1.php', and will finally fall back to
* tag.php template, if those files don't exist.
*
* The template path is filterable via the dynamic {@see '$type_template'} hook,
* e.g. 'tag_template'.
*
* @since 2.3.0
*
* @see get_query_template()
*
* @return string Full path to tag template file.
*/
function get_tag_template()
{
$tag = get_queried_object();
$templates = array();
if (!empty($tag->slug)) {
$templates[] = "tag-{$tag->slug}.php";
$templates[] = "tag-{$tag->term_id}.php";
}
$templates[] = 'tag.php';
return get_query_template('tag', $templates);
}