wppaste
WordPress

apply_filters( "{$type}_template", string $template, string $type, string[] $templates )

Since
1.5.0, 4.8.0
Filters the path of the queried template by type.

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

Compatibility

WordPress
since 4.8.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Parameters

$templatestring
Path to the template. See locate_template().
$typestring
Sanitized filename without extension.
$templatesstring[]
A list of template candidates, in descending order of priority.

Where this hook fires · 1

  • wp-includes/template.php:103get_query_template()

Source code

	 * @since 4.8.0 The `$type` and `$templates` parameters were added.	 *	 * @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 apply_filters( "{$type}_template", $template, $type, $templates );} /** * Retrieves path of index template in current or parent template. * * The template hierarchy and template path are filterable via the {@see '$type_template_hierarchy'}

Changelog

Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

4.8.0
The $type and $templates parameters were added.from the docblock
1.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.