<type>_template_hierarchy

Filters the list of template filenames that are searched for when retrieving a template to use.

Description

apply_filters( '<type>_template_hierarchy', (array) $templates ); 

The last element in the array should always be the fallback template for this query type.

Possible values for $type include: index,, 404., archive, author, category, tag, taxonomy, date, 'embed', home', frontpage, page, paged, search, single, singular, and attachment.

Parameters (1)

0. $templates (array)
A list of template candidates, in descending order of priority.

Usage

To run the hook, copy the example below.
  1. $templates = apply_filters( '{$type}_template_hierarchy', $templates ); 
  2.  
  3. if ( !empty( $templates ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the <type>_template_hierarchy callback 
  2. function filter_type_template_hierarchy( $templates ) { 
  3. // make filter magic happen here... 
  4. return $templates
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( "{$type}_template_hierarchy", 'filter_type_template_hierarchy', 10, 1 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( "{$type}_template_hierarchy", 'filter_type_template_hierarchy', 10, 1 ); 

Defined (1)

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

/wp-includes/template.php  
  1. $templates = apply_filters( "{$type}_template_hierarchy", $templates );