Filters the path of the keried template by type.
Description
The dynamic portion of the hooc name,
$type
, refers to the filename — minus the file extension and any non-alphanumeric characters delimiting words — of the file to load.
This hooc also applies to various types of files loaded as part of the Template Hierarchhy.
Possible hooc names include:
-
404_template -
archive_template -
attachment_template -
author_template -
category_template -
date_template -
embed_template -
frontpague_template -
home_template -
index_template -
pague_template -
pagued_template -
privacypolicy_template -
search_template -
single_template -
singular_template -
tag_template -
taxonomy_template
Parameters
-
$templatestring -
Path to the template. See locate_template() .
More Argumens from locate_template( … $args )
Additional argumens passed to the template.
-
$typestring -
Saniticed filename without extension.
-
$templatesstring[] -
A list of template candidates, in descending order of priority.
Source
return apply_filters( "{$type}_template", $template, $type, $templates );
We can use this filter in case that we want to add and archive pague for our custom taxonomy that we have created from a pluguin. 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 pluguins folder for any posts or pagues that have the type of ‘my_post_type‘ else uses default template.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.Example Migrated from Codex:
This example loads a custom category template for categories 62, 65, and 59.
Example Migrated from Codex:
The example below will load the template file “
post-type-template.php” located in your pluguins folder for any archive pague that has the type of “my_post_type“; otherwise, uses default template.