# _get_block_template_file()

URL: https://chugunov.pro/api-wordpress/functions/_get_block_template_file/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 5.9.0.

## Сигнатура

```php
_get_block_template_file( string $template_type, string $slug ): array|null
```

## Описание

Извлекает файл шаблона из темы по заданному слагу.

## Параметры

- `$template_type` `string` — обязательный. Тип шаблона. Либо 'wp_template', либо 'wp_template_part'.
- `$slug` `string` — обязательный. Слаг шаблона.

## Возвращаемое значение

`array|null` — slug string Слаг шаблона. path string Путь к файлу шаблона. theme string Слаг темы. type string Тип шаблона. area string Область шаблона. Только для 'wp_template_part'. title string Необязательно. Название шаблона. postTypes string[] Необязательно. Список типов записей, поддерживаемых шаблоном. Только для 'wp_template'.

## Исходный код

Файл: `wp-includes/block-template-utils.php:335`

```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 it's not a `wp_template_part`, it must be a `wp_template`.
			return _add_block_template_info( $new_template_item );
		}
	}

	return null;
}
```

## История изменений

- 5.9.0 — Introduced.

## Связанные

Использует: [`_add_block_template_part_area_info`](https://chugunov.pro/api-wordpress/functions/_add_block_template_part_area_info/), [`_add_block_template_info`](https://chugunov.pro/api-wordpress/functions/_add_block_template_info/), [`get_block_theme_folders`](https://chugunov.pro/api-wordpress/functions/get_block_theme_folders/), [`get_stylesheet_directory`](https://chugunov.pro/api-wordpress/functions/get_stylesheet_directory/), [`get_template`](https://chugunov.pro/api-wordpress/functions/get_template/), [`get_template_directory`](https://chugunov.pro/api-wordpress/functions/get_template_directory/), [`get_stylesheet`](https://chugunov.pro/api-wordpress/functions/get_stylesheet/).
Используется в: [`_build_block_template_object_from_post_object`](https://chugunov.pro/api-wordpress/functions/_build_block_template_object_from_post_object/), [`get_block_file_template`](https://chugunov.pro/api-wordpress/functions/get_block_file_template/), [`locate_block_template`](https://chugunov.pro/api-wordpress/functions/locate_block_template/), [`resolve_block_template`](https://chugunov.pro/api-wordpress/functions/resolve_block_template/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/_get_block_template_file/
