Filter hook 'pre_get_block_templates'

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

View Source

pre_get_block_templates

Filter Hook
Description
Filters the block templates array 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 1116

Hook Parameters

Type Name Description
WP_Block_Template[]|null $block_templates Return an array of block templates to short-circuit the default query, or null to allow WP to run its normal queries.
array $query { Arguments to retrieve templates. All arguments are optional.
string $template_type Template type. Either 'wp_template' or 'wp_template_part'.

Usage Examples

Basic Usage
<?php
// Hook into pre_get_block_templates
add_filter('pre_get_block_templates', 'my_custom_filter', 10, 3);

function my_custom_filter($block_templates, $query, $template_type) {
    // Your custom filtering logic here
    return $block_templates;
}

Source Code Context

wp-includes/block-template-utils.php:1116 - How this hook is used in WordPress core
<?php
1111  	 *     @type string   $area      A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).
1112  	 *     @type string   $post_type Post type to get the templates for.
1113  	 * }
1114  	 * @param string $template_type Template type. Either 'wp_template' or 'wp_template_part'.
1115  	 */
1116  	$templates = apply_filters( 'pre_get_block_templates', null, $query, $template_type );
1117  	if ( ! is_null( $templates ) ) {
1118  		return $templates;
1119  	}
1120  
1121  	$post_type     = isset( $query['post_type'] ) ? $query['post_type'] : '';

PHP Documentation

<?php
/**
	 * Filters the block templates array 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_templates Return an array of block templates to short-circuit the default query,
	 *                                                  or null to allow WP to run its normal queries.
	 * @param array  $query {
	 *     Arguments to retrieve templates. All arguments are optional.
	 *
	 *     @type string[] $slug__in  List of slugs to include.
	 *     @type int      $wp_id     Post ID of customized template.
	 *     @type string   $area      A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).
	 *     @type string   $post_type Post type to get the templates for.
	 * }
	 * @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.