pre_get_block_file_template
Filter HookDescription
Filters the block template object before the theme file discovery takes place. Return a non-null value to bypass the WordPress theme file discovery.Hook Information
File Location |
wp-includes/block-template-utils.php
View on GitHub
|
Hook Type | Filter |
Line Number | 1353 |
Hook Parameters
Type | Name | Description |
---|---|---|
WP_Block_Template|null
|
$block_template
|
Return block template object to short-circuit the default query, or null to allow WP to run its normal queries. |
string
|
$id
|
Template unique identifier (example: 'theme_slug//template_slug'). |
string
|
$template_type
|
Template type. Either 'wp_template' or 'wp_template_part'. |
Usage Examples
Basic Usage
<?php
// Hook into pre_get_block_file_template
add_filter('pre_get_block_file_template', 'my_custom_filter', 10, 3);
function my_custom_filter($block_template, $id, $template_type) {
// Your custom filtering logic here
return $block_template;
}
Source Code Context
wp-includes/block-template-utils.php:1353
- How this hook is used in WordPress core
<?php
1348 * @param WP_Block_Template|null $block_template Return block template object to short-circuit the default query,
1349 * or null to allow WP to run its normal queries.
1350 * @param string $id Template unique identifier (example: 'theme_slug//template_slug').
1351 * @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
1352 */
1353 $block_template = apply_filters( 'pre_get_block_file_template', null, $id, $template_type );
1354 if ( ! is_null( $block_template ) ) {
1355 return $block_template;
1356 }
1357
1358 $parts = explode( '//', $id, 2 );
PHP Documentation
<?php
/**
* Filters the block template object before the theme file discovery takes place.
*
* Return a non-null value to bypass the WordPress theme file discovery.
*
* @since 5.9.0
*
* @param WP_Block_Template|null $block_template Return block template object to short-circuit the default query,
* or null to allow WP to run its normal queries.
* @param string $id Template unique identifier (example: 'theme_slug//template_slug').
* @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
*/
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.