apply_filters( "{$type}_template", string $template , string $type , string[] $templates )
Filters the path of the queried template by type.
Contents
Description Description
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
Parameters Parameters
- $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.
More Information More Information
If you need more granular control over the template selection and loading system of WordPress, consider using template_include instead.
Source Source
File: wp-includes/template.php
Changelog Changelog
Version | Description |
---|---|
4.8.0 | The $type and $templates parameters were added. |
1.5.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
We can use this filter in case that we want to add and archive page for our custom taxonomy that we have created from a plugin. In this case the filter we will need is “taxonomy_template”.
Example Migrated from Codex:
The example code will load the template file “
post-type-template.php
” located in your plugins folder for any posts or pages that have the type of ‘my_post_type
‘ else uses default template.Expand full source codeCollapse full source code
Example Migrated from Codex:
This example loads the template file
single-{post_type}-{slug}.php
(e.g.single-event-wordcamp.php
) only if the file exists, otherwise loads default template.Expand full source codeCollapse full source code
Example Migrated from Codex:
This example loads a custom category template for categories 62, 65, and 59.
Expand full source codeCollapse full source code
Example Migrated from Codex:
The example below will load the template file “
post-type-template.php
” located in your plugins folder for any archive page that has the type of “my_post_type
“; otherwise, uses default template.