pre_get_block_templates filter-hookWP 5.9.0

Filters the block templates array before the query takes place.

Return a non-null value to bypass the WordPress queries.

Usage

add_filter( 'pre_get_block_templates', 'wp_kama_pre_get_block_templates_filter', 10, 3 );

/**
 * Function for `pre_get_block_templates` filter-hook.
 * 
 * @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.
 * @param string                   $template_type   Template type. Either 'wp_template' or 'wp_template_part'.
 *
 * @return WP_Block_Template[]|null
 */
function wp_kama_pre_get_block_templates_filter( $block_templates, $query, $template_type ){

	// filter...
	return $block_templates;
}
$block_templates(WP_Block_Template[]|null)
Return an array of block templates to short-circuit the default query, or null to allow WP to run its normal queries.
$query(array)

Arguments to retrieve templates. All arguments are optional.

  • slug__in(string[])
    List of slugs to include.

  • wp_id(int)
    Post ID of customized template.

  • area(string)
    A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).

  • post_type(string)
    Post type to get the templates for.
$template_type(string)
Template type. Either 'wp_template' or 'wp_template_part'.

Changelog

Since 5.9.0 Introduced.

Where the hook is called

get_block_templates()
pre_get_block_templates
wp-includes/block-template-utils.php 949
$templates = apply_filters( 'pre_get_block_templates', null, $query, $template_type );

Where the hook is used in WordPress

Usage not found.