{$template_type}_template_hierarchy
Filter HookDescription
Gets the template hierarchy for the given template slug to be created. Note: Always add `index` as the last fallback template.Hook Information
File Location |
wp-includes/block-template-utils.php
View on GitHub
|
Hook Type | Filter |
Line Number | 1651 |
Hook Parameters
Type | Name | Description |
---|---|---|
string
|
$slug
|
The template slug to be created. |
bool
|
$is_custom
|
Optional. Indicates if a template is custom or part of the template hierarchy. Default false. |
string
|
$template_prefix
|
Optional. The template prefix for the created template. Used to extract the main template type, e.g. in `taxonomy-books` the `taxonomy` is extracted. Default empty string. |
Usage Examples
Basic Usage
<?php
// Hook into {$template_type}_template_hierarchy
add_filter('{$template_type}_template_hierarchy', 'my_custom_filter', 10, 3);
function my_custom_filter($slug, $is_custom, $template_prefix) {
// Your custom filtering logic here
return $slug;
}
Source Code Context
wp-includes/block-template-utils.php:1651
- How this hook is used in WordPress core
<?php
1646 list( $template_type ) = explode( '-', $slug );
1647 }
1648 $valid_template_types = array( '404', 'archive', 'attachment', 'author', 'category', 'date', 'embed', 'frontpage', 'home', 'index', 'page', 'paged', 'privacypolicy', 'search', 'single', 'singular', 'tag', 'taxonomy' );
1649 if ( in_array( $template_type, $valid_template_types, true ) ) {
1650 /** This filter is documented in wp-includes/template.php */
1651 return apply_filters( "{$template_type}_template_hierarchy", $template_hierarchy );
1652 }
1653 return $template_hierarchy;
1654 }
1655
1656 /**
PHP Documentation
<?php
/**
* Gets the template hierarchy for the given template slug to be created.
*
* Note: Always add `index` as the last fallback template.
*
* @since 6.1.0
*
* @param string $slug The template slug to be created.
* @param bool $is_custom Optional. Indicates if a template is custom or
* part of the template hierarchy. Default false.
* @param string $template_prefix Optional. The template prefix for the created template.
* Used to extract the main template type, e.g.
* in `taxonomy-books` the `taxonomy` is extracted.
* Default empty string.
* @return string[] The template hierarchy.
*/
Quick Info
- Hook Type: Filter
- Parameters: 3
- File: wp-includes/block-template-utils.php
Related Hooks
Related hooks will be displayed here in future updates.