theme_<post_type>_templates

Filters list of page templates for a theme.

Description

apply_filters( 'theme_<post_type>_templates', (array) $post_templates, (WP_Theme) $instance, (WP_Post|null) $post, (string) $post_type ); 

The dynamic portion(s) of the hook name refer to the post type.

Parameters (4)

0. $post_templates (array)
Array of page templates. Keys are filenames, values are translated names.
1. $instance (WP_Theme)
The theme object.
2. $post (WP_Post|null)
The post being edited, provided for context, or null.
3. $post_type (string)
Post type to get the templates for.

Usage

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

Defined (1)

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

/wp-includes/class-wp-theme.php  
  1. return (array) apply_filters( "theme_{$post_type}_templates", $post_templates, $this, $post, $post_type );