Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
_get_block_template_file() WordPress Function
The get_block_template_file() function is used to get the path of the template file for a given block. This function is useful for getting the path of a template file for a specific block. For example, if you want to get the path of the template file for the "Recent Posts" block, you would use this function. The get_block_template_file() function takes one parameter, which is the name of the block for which you want to get the template file path. This function returns the path of the template file for the given block.
_get_block_template_file( string $template_type, string $slug ) #
Retrieves the template file from the theme for a given slug.
Parameters
- $template_type
(string)(Required)'wp_template' or 'wp_template_part'.
- $slug
(string)(Required)Template slug.
Return
(array|null) Template.
Source
File: wp-includes/block-template-utils.php
function _get_block_template_file( $template_type, $slug ) { if ( 'wp_template' !== $template_type && 'wp_template_part' !== $template_type ) { return null; } $themes = array( get_stylesheet() => get_stylesheet_directory(), get_template() => get_template_directory(), ); foreach ( $themes as $theme_slug => $theme_dir ) { $template_base_paths = get_block_theme_folders( $theme_slug ); $file_path = $theme_dir . '/' . $template_base_paths[ $template_type ] . '/' . $slug . '.html'; if ( file_exists( $file_path ) ) { $new_template_item = array( 'slug' => $slug, 'path' => $file_path, 'theme' => $theme_slug, 'type' => $template_type, ); if ( 'wp_template_part' === $template_type ) { return _add_block_template_part_area_info( $new_template_item ); } if ( 'wp_template' === $template_type ) { return _add_block_template_info( $new_template_item ); } return $new_template_item; } } return null; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.9.0 | Introduced. |