Filter hook 'theme_{$post_type}_templates'

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

View Source

theme_{$post_type}_templates

Filter Hook
Description
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`

Hook Information

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

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_{$post_type}_templates
add_filter('theme_{$post_type}_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:1434 - How this hook is used in WordPress core
<?php
1429  		 * @param string[]     $post_templates Array of template header names keyed by the template file name.
1430  		 * @param WP_Theme     $theme          The theme object.
1431  		 * @param WP_Post|null $post           The post being edited, provided for context, or null.
1432  		 * @param string       $post_type      Post type to get the templates for.
1433  		 */
1434  		$post_templates = (array) apply_filters( "theme_{$post_type}_templates", $post_templates, $this, $post, $post_type );
1435  
1436  		return $post_templates;
1437  	}
1438  
1439  	/**

PHP Documentation

<?php
/**
		 * 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`
		 *
		 * @since 3.9.0
		 * @since 4.4.0 Converted to allow complete control over the `$page_templates` array.
		 * @since 4.7.0 Added the `$post_type` parameter.
		 *
		 * @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.