apply_filters( "theme_{$post_type}_templates", string[] $post_templates, WP_Theme $theme, WP_Post|null $post, string $post_type )
- Since
- 3.9.0, 4.4.0, 4.7.0
Filters list of page templates for a theme.
Description
The dynamic portion of the hook name, $post_type, refers to the post type.
Possible hook names include:
theme_post_templatestheme_page_templatestheme_attachment_templates
Compatibility
- WordPress
- since 4.7.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
$post_templatesstring[]- Array of template header names keyed by the template file name.
$themeWP_Theme- The theme object.
$postWP_Post|null- The post being edited, provided for context, or null.
$post_typestring- Post type to get the templates for.
Where this hook fires · 1
wp-includes/class-wp-theme.php:1434WP_Theme::get_page_templates()
Source code
* * @param string[] $post_templates Array of template header names keyed by the template file name. * @param WP_Theme $theme The theme object. * @param WP_Post|null $post The post being edited, provided for context, or null. * @param string $post_type Post type to get the templates for. */ $post_templates = (array) apply_filters( "theme_{$post_type}_templates", $post_templates, $this, $post, $post_type ); return $post_templates; } /** * Scans a directory for files of a certain extension.Changelog
Introduced in 3.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
4.7.0
Added the
$post_type parameter.from the docblock4.4.0
Converted to allow complete control over the
$page_templates array.from the docblock3.9.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.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.