theme_(post_type)_templates
Filters list of page templates for a theme.
The dynamic portion of the hook name, $post_type, refers to the post type.
Possible hook names include:
Usage
add_filter( 'theme_(post_type)_templates', 'wp_kama_theme_post_type_templates_filter', 10, 4 ); /** * Function for `theme_(post_type)_templates` filter-hook. * * @param string[] $post_templates Array of template header names keyed by the template file name. * @param WP_Theme $theme The theme object. * @param WP_Post|null $post The post being edited, provided for context, or null. * @param string $post_type Post type to get the templates for. * * @return string[] */ function wp_kama_theme_post_type_templates_filter( $post_templates, $theme, $post, $post_type ){ // filter... return $post_templates; }
- $post_templates(string[])
- Array of template header names keyed by the template file name.
- $theme(WP_Theme)
- The theme object.
- $post(WP_Post|null)
- The post being edited, provided for context, or null.
- $post_type(string)
- Post type to get the templates for.
Changelog
Since 3.9.0 | Introduced. |
Since 4.4.0 | Converted to allow complete control over the $page_templates array. |
Since 4.7.0 | Added the $post_type parameter. |
Where the hook is called
theme_(post_type)_templates
wp-includes/class-wp-theme.php 1374
$post_templates = (array) apply_filters( "theme_{$post_type}_templates", $post_templates, $this, $post, $post_type );
Where the hook is used in WordPress
wp-includes/default-filters.php 620
add_filter( 'theme_wp_navigation_templates', '__return_empty_array' );