apply_filters( "theme_{$post_type}_templates", string[] $post_templates, WP_Theme $theme, WP_Post|null $post, string $post_type )

Filters list of page templates for a theme.


The dynamic portion of the hook name, $post_type, refers to the post type.

Possible hook names include:

  • theme_post_templates
  • theme_page_templates
  • theme_attachment_templates

Top ↑


$post_templates string[]
Array of template header names keyed by the template file name.
$theme WP_Theme
The theme object.
$post WP_Post|null
The post being edited, provided for context, or null.
$post_type string
Post type to get the templates for.

Top ↑


File: wp-includes/class-wp-theme.php. View all references

$post_templates = (array) apply_filters( "theme_{$post_type}_templates", $post_templates, $this, $post, $post_type );

Top ↑


Version Description
4.7.0 Added the $post_type parameter.
4.4.0 Converted to allow complete control over the $page_templates array.
3.9.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.