Filter hook 'pre_get_block_template'

in WP Core File wp-includes/block-template-utils.php at line 1279

View Source

pre_get_block_template

Filter Hook
Description
Filters the block template object before the query takes place. Return a non-null value to bypass the WordPress queries.

Hook Information

File Location wp-includes/block-template-utils.php View on GitHub
Hook Type Filter
Line Number 1279

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_template
add_filter('pre_get_block_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:1279 - How this hook is used in WordPress core
<?php
1274  	 * @param WP_Block_Template|null $block_template Return block template object to short-circuit the default query,
1275  	 *                                               or null to allow WP to run its normal queries.
1276  	 * @param string                 $id             Template unique identifier (example: 'theme_slug//template_slug').
1277  	 * @param string                 $template_type  Template type. Either 'wp_template' or 'wp_template_part'.
1278  	 */
1279  	$block_template = apply_filters( 'pre_get_block_template', null, $id, $template_type );
1280  	if ( ! is_null( $block_template ) ) {
1281  		return $block_template;
1282  	}
1283  
1284  	$parts = explode( '//', $id, 2 );

PHP Documentation

<?php
/**
	 * Filters the block template object before the query takes place.
	 *
	 * Return a non-null value to bypass the WordPress queries.
	 *
	 * @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.