Filter hook 'theme_templates'

in WP Core File wp-includes/class-wp-theme.php at line 1412

View Source

theme_templates

Filter Hook
Description
Filters list of page templates for a theme.

Hook Information

File Location wp-includes/class-wp-theme.php View on GitHub
Hook Type Filter
Line Number 1412

Hook Parameters

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

Usage Examples

Basic Usage
<?php
// Hook into theme_templates
add_filter('theme_templates', 'my_custom_filter', 10, 4);

function my_custom_filter($post_templates, $theme, $post, $post_type) {
    // Your custom filtering logic here
    return $post_templates;
}

Source Code Context

wp-includes/class-wp-theme.php:1412 - How this hook is used in WordPress core
<?php
1407  		 * @param string[]     $post_templates Array of template header names keyed by the template file name.
1408  		 * @param WP_Theme     $theme          The theme object.
1409  		 * @param WP_Post|null $post           The post being edited, provided for context, or null.
1410  		 * @param string       $post_type      Post type to get the templates for.
1411  		 */
1412  		$post_templates = (array) apply_filters( 'theme_templates', $post_templates, $this, $post, $post_type );
1413  
1414  		/**
1415  		 * Filters list of page templates for a theme.
1416  		 *
1417  		 * The dynamic portion of the hook name, `$post_type`, refers to the post type.

PHP Documentation

<?php
/**
		 * Filters list of page templates for a theme.
		 *
		 * @since 4.9.6
		 *
		 * @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.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 4
  • File: wp-includes/class-wp-theme.php
Related Hooks

Related hooks will be displayed here in future updates.