# _inject_theme_attribute_in_block_template_content()

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

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

> Устаревший элемент. Помечен устаревшим с версии 6.4.0.

## Сигнатура

```php
_inject_theme_attribute_in_block_template_content( string $template_content ): string
```

## Описание

Разбирает содержимое wp_template и вставляет таблицу стилей активной темы в виде атрибута theme в каждый wp_template_part.

## Параметры

- `$template_content` `string` — обязательный. Сериализованное содержимое wp_template.

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

`string` — 'wp_template'

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

Файл: `wp-includes/deprecated.php:6061`

```php
function _inject_theme_attribute_in_block_template_content( $template_content ) {
	_deprecated_function(
		__FUNCTION__,
		'6.4.0',
		'traverse_and_serialize_blocks( parse_blocks( $template_content ), "_inject_theme_attribute_in_template_part_block" )'
	);

	$has_updated_content = false;
	$new_content         = '';
	$template_blocks     = parse_blocks( $template_content );

	$blocks = _flatten_blocks( $template_blocks );
	foreach ( $blocks as &$block ) {
		if (
			'core/template-part' === $block['blockName'] &&
			! isset( $block['attrs']['theme'] )
		) {
			$block['attrs']['theme'] = get_stylesheet();
			$has_updated_content     = true;
		}
	}

	if ( $has_updated_content ) {
		foreach ( $template_blocks as &$block ) {
			$new_content .= serialize_block( $block );
		}

		return $new_content;
	}

	return $template_content;
}
```

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

- 6.4.0 — Deprecated. Use traverse_and_serialize_blocks( parse_blocks( $template_content ), '_inject_theme_attribute_in_template_part_block' ) instead.
- 5.9.0 — Introduced.

## Связанные

Использует: [`_flatten_blocks`](https://chugunov.pro/api-wordpress/functions/_flatten_blocks/), [`serialize_block`](https://chugunov.pro/api-wordpress/functions/serialize_block/), [`parse_blocks`](https://chugunov.pro/api-wordpress/functions/parse_blocks/), [`get_stylesheet`](https://chugunov.pro/api-wordpress/functions/get_stylesheet/), [`_deprecated_function`](https://chugunov.pro/api-wordpress/functions/_deprecated_function/).

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