(type)_template
Filters the path of the queried template by type.
The dynamic portion of the hook name, $type, refers to the filename -- minus the file extension and any non-alphanumeric characters delimiting words -- of the file to load. This hook also applies to various types of files loaded as part of the Template Hierarchy.
Possible hook names include:
- 404_template
- archive_template
- attachment_template
- author_template
- category_template
- date_template
- embed_template
- frontpage_template
- home_template
- index_template
- page_template
- paged_template
- privacypolicy_template
- search_template
- single_template
- singular_template
- tag_template
- taxonomy_template
Usage
add_filter( '(type)_template', 'wp_kama_type_template_filter', 10, 3 ); /** * Function for `(type)_template` filter-hook. * * @param string $template Path to the template. See locate_template(). * @param string $type Sanitized filename without extension. * @param string[] $templates A list of template candidates, in descending order of priority. * * @return string */ function wp_kama_type_template_filter( $template, $type, $templates ){ // filter... return $template; }
- $template(string)
- Path to the template. See locate_template().
- $type(string)
- Sanitized filename without extension.
- $templates(string[])
- A list of template candidates, in descending order of priority.
Changelog
Since 1.5.0 | Introduced. |
Since 4.8.0 | The $type and $templates parameters were added. |
Where the hook is called
(type)_template
wp-includes/template.php 103
return apply_filters( "{$type}_template", $template, $type, $templates );
Where the hook is used in WordPress
wp-includes/class-wp-customize-manager.php 694
add_filter( 'pre_option_template', array( $this, 'get_template' ) );
wp-includes/class-wp-customize-manager.php 732
remove_filter( 'pre_option_template', array( $this, 'get_template' ) );
wp-includes/default-filters.php 757
add_filter( 'rest_pre_insert_wp_template', 'inject_ignored_hooked_blocks_metadata_attributes' );