pre_get_block_templates WordPress Filter Hook

The pre_get_block_templates hook is used to modify the list of block templates that are available for a given post type. This hook is called before the list of block templates is retrieved, and allows for customizations such as adding or removing templates, or changing the order in which they are returned.

apply_filters( 'pre_get_block_templates', WP_Block_Template[]|null $block_templates, array $query, string $template_type ) #

Filters the block templates array before the query takes place.


Description

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


Top ↑

Parameters

$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 it's normal queries.

$query

(array)Arguments to retrieve templates.

  • 'slug__in'
    (array) List of slugs to include.
  • 'wp_id'
    (int) Post ID of customized template.
  • 'post_type'
    (string) Post type to get the templates for.

$template_type

(string)wp_template or wp_template_part.


Top ↑

Source

File: wp-includes/block-template-utils.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
5.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.