Title: {$type}_template
Published: April 25, 2014
Last modified: April 28, 2025

---

# apply_filters( “{$type}_template”, string $template, string $type, string[] $templates )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#wp--skip-link--target)

Filters the path of the queried template by type.

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#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](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#parameters)󠁿

 `$template`string

Path to the template. See [locate_template()](https://developer.wordpress.org/reference/functions/locate_template/).

More Arguments from locate_template( … $args )

Additional arguments passed to the template.

`$type`string

Sanitized filename without extension.

`$templates`string[]

A list of template candidates, in descending order of priority.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#more-information)󠁿

If you need more granular control over the template selection and loading system
of WordPress, consider using [template_include](https://developer.wordpress.org/reference/hooks/template_include/)
instead.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#source)󠁿

    ```php
    return apply_filters( "{$type}_template", $template, $type, $templates );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/template.php#L103)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/template.php#L103-L103)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#related)󠁿

| Used by | Description | 
| [get_query_template()](https://developer.wordpress.org/reference/functions/get_query_template/)`wp-includes/template.php` |

Retrieves path to a template.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | The `$type` and `$templates` parameters were added. | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 6 content](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#comment-content-2720)
 2.    [alordiel](https://profiles.wordpress.org/alordiel/)  [  8 years ago  ](https://developer.wordpress.org/reference/hooks/type_template/#comment-2720)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%23comment-2720)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%23comment-2720)
 4.  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”_.
 5.      ```php
         add_filter( "taxonomy_template", 'load_our_custom_tax_template');
         function load_our_custom_tax_template ($tax_template) {
           if (is_tax('custom-tax-name')) {
             $tax_template = dirname(  __FILE__  ) . '/templates/custom-taxonomy-template.php';
           }
           return $tax_template;
         }
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%3Freplytocom%3D2720%23feedback-editor-2720)
 7.   [Skip to note 7 content](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#comment-content-4211)
 8.    [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  6 years ago  ](https://developer.wordpress.org/reference/hooks/type_template/#comment-4211)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%23comment-4211)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%23comment-4211)
 10. Example Migrated from Codex:
 11. 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.
 12.     ```php
         <?php
         add_filter( 'single_template', 'get_custom_post_type_template' );
     
         function get_custom_post_type_template( $single_template ) {
         	global $post;
     
         	if ( 'my_post_type' === $post->post_type ) {
         		$single_template = dirname( __FILE__ ) . '/post-type-template.php';
         	}
     
         	return $single_template;
         }
         ?>
         ```
     
 13.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%3Freplytocom%3D4211%23feedback-editor-4211)
 14.  [Skip to note 8 content](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#comment-content-4212)
 15.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  6 years ago  ](https://developer.wordpress.org/reference/hooks/type_template/#comment-4212)
 16. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%23comment-4212)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%23comment-4212)
 17. Example Migrated from Codex:
 18. 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.
 19.     ```php
         <?php
         add_filter( 'single_template', 'add_postType_slug_template', 10, 1 );
     
         function add_posttype_slug_template( $single_template ) {
         	$object                            = get_queried_object();
         	$single_posttype_postname_template = locate_template( "single-{$object->post_type}-{$object->post_name}.php" );
     
         	if ( file_exists( $single_posttype_postname_template ) ) {
         		return $single_posttype_postname_template;
         	} else {
         		return $single_template;
         	}
         }
         ?>
         ```
     
 20.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%3Freplytocom%3D4212%23feedback-editor-4212)
 21.  [Skip to note 9 content](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#comment-content-4683)
 22.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/type_template/#comment-4683)
 23. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%23comment-4683)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%23comment-4683)
 24. Example Migrated from Codex:
 25. This example loads a custom category template for categories 62, 65, and 59.
 26.     ```php
         add_filter( 'category_template', 'filter_category_template', 99 );
     
         function filter_category_template( $template ) {
     
         	 if ( is_category(array( 64,65,59 )  )  ) {
         		$new_template = locate_template( array( 'category-template.php' ) );
         		if ( '' != $new_template ) {
         			return $new_template;
         		}
         	}
     
         	return $template;
         }
         ```
     
 27.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%3Freplytocom%3D4683%23feedback-editor-4683)
 28.  [Skip to note 10 content](https://developer.wordpress.org/reference/hooks/type_template/?output_format=md#comment-content-4754)
 29.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/type_template/#comment-4754)
 30. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%23comment-4754)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%23comment-4754)
 31. Example Migrated from Codex:
 32. 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.
 33.     ```php
         add_filter( 'archive_template', 'get_custom_post_type_template' );
     
         function get_custom_post_type_template( $archive_template ) {
              global $post;
     
              if ( is_post_type_archive ( 'my_post_type' ) ) {
                   $archive_template = dirname( __FILE__ ) . '/post-type-template.php';
              }
              return $archive_template;
         }
         ```
     
 34.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F%3Freplytocom%3D4754%23feedback-editor-4754)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Ftype_template%2F)
before being able to contribute a note or feedback.