# get_the_block_template_html()

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

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

## Сигнатура

```php
get_the_block_template_html(): string
```

## Описание

Возвращает разметку текущего шаблона.

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

`string`

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

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

```php
function get_the_block_template_html() {
	global $_wp_current_template_id, $_wp_current_template_content, $wp_embed, $wp_query;

	if ( ! $_wp_current_template_content ) {
		if ( is_user_logged_in() ) {
			return '<h1>' . esc_html__( 'No matching template found' ) . '</h1>';
		}
		return '';
	}

	$content = $wp_embed->run_shortcode( $_wp_current_template_content );
	$content = $wp_embed->autoembed( $content );
	$content = shortcode_unautop( $content );
	$content = do_shortcode( $content );

	/*
	 * Most block themes omit the `core/query` and `core/post-template` blocks in their singular content templates.
	 * While this technically still works since singular content templates are always for only one post, it results in
	 * the main query loop never being entered which causes bugs in core and the plugin ecosystem.
	 *
	 * The workaround below ensures that the loop is started even for those singular templates. The while loop will by
	 * definition only go through a single iteration, i.e. `do_blocks()` is only called once. Additional safeguard
	 * checks are included to ensure the main query loop has not been tampered with and really only encompasses a
	 * single post.
	 *
	 * Even if the block template contained a `core/query` and `core/post-template` block referencing the main query
	 * loop, it would not cause errors since it would use a cloned instance and go through the same loop of a single
	 * post, within the actual main query loop.
	 *
	 * This special logic should be skipped if the current template does not come from the current theme, in which case
	 * it has been injected by a plugin by hijacking the block template loader mechanism. In that case, entirely custom
	 * logic may be applied which is unpredictable and therefore safer to omit this special handling on.
	 */
	if (
		$_wp_current_template_id &&
		str_starts_with( $_wp_current_template_id, get_stylesheet() . '//' ) &&
		is_singular() &&
		1 === $wp_query->post_count &&
		have_posts()
	) {
		while ( have_posts() ) {
			the_post();
			$content = do_blocks( $content );
		}
	} else {
		$content = do_blocks( $content );
	}

	$content = wptexturize( $content );
	$content = convert_smilies( $content );
	$content = wp_filter_content_tags( $content, 'template' );
	$content = str_replace( ']]>', ']]&gt;', $content );

	// Wrap block template in .wp-site-blocks to allow for specific descendant styles
	// (e.g. `.wp-site-blocks > *`).
	$template_html = '<div class="wp-site-blocks">' . $content . '</div>';

	// Back-compat for plugins that disable functionality by unhooking one of these actions.
	if (
		! has_action( 'wp_footer', 'the_block_template_skip_link' ) ||
		! has_action( 'wp_enqueue_scripts', 'wp_enqueue_block_template_skip_link' )
	) {
		return $template_html;
	}

	return _block_template_add_skip_link( $template_html );
}
```

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

- 5.8.0 — Introduced.

## Связанные

Использует: [`_block_template_add_skip_link`](https://chugunov.pro/api-wordpress/functions/_block_template_add_skip_link/), [`wp_filter_content_tags`](https://chugunov.pro/api-wordpress/functions/wp_filter_content_tags/), [`do_blocks`](https://chugunov.pro/api-wordpress/functions/do_blocks/), [`get_stylesheet`](https://chugunov.pro/api-wordpress/functions/get_stylesheet/), [`esc_html__`](https://chugunov.pro/api-wordpress/functions/esc_html__/), [`convert_smilies`](https://chugunov.pro/api-wordpress/functions/convert_smilies/), [`shortcode_unautop`](https://chugunov.pro/api-wordpress/functions/shortcode_unautop/), [`wptexturize`](https://chugunov.pro/api-wordpress/functions/wptexturize/), [`is_singular`](https://chugunov.pro/api-wordpress/functions/is_singular/), [`have_posts`](https://chugunov.pro/api-wordpress/functions/have_posts/), [`the_post`](https://chugunov.pro/api-wordpress/functions/the_post/), `WP_Embed::autoembed`, `WP_Embed::shortcode`, `WP_Embed::run_shortcode`, [`do_shortcode`](https://chugunov.pro/api-wordpress/functions/do_shortcode/), [`has_action`](https://chugunov.pro/api-wordpress/functions/has_action/), [`is_user_logged_in`](https://chugunov.pro/api-wordpress/functions/is_user_logged_in/).

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