index_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 | 1567 |
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 index_template_hierarchy
add_filter('index_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:1567
- How this hook is used in WordPress core
<?php
1562 * @return string[] The template hierarchy.
1563 */
1564 function get_template_hierarchy( $slug, $is_custom = false, $template_prefix = '' ) {
1565 if ( 'index' === $slug ) {
1566 /** This filter is documented in wp-includes/template.php */
1567 return apply_filters( 'index_template_hierarchy', array( 'index' ) );
1568 }
1569 if ( $is_custom ) {
1570 /** This filter is documented in wp-includes/template.php */
1571 return apply_filters( 'page_template_hierarchy', array( 'page', 'singular', 'index' ) );
1572 }
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.