# do_blocks()

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

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

## Сигнатура

```php
do_blocks( string $content ): string
```

## Описание

Разбирает динамические блоки из `post_content` и повторно отображает их.

## Параметры

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

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

`string`

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

Файл: `wp-includes/blocks.php:2496`

```php
function do_blocks( $content ) {
	$blocks                = parse_blocks( $content );
	$top_level_block_count = count( $blocks );
	$output                = '';

	/**
	 * Parsed blocks consist of a list of top-level blocks. Those top-level
	 * blocks may themselves contain nested inner blocks. However, every
	 * top-level block is rendered independently, meaning there are no data
	 * dependencies between them.
	 *
	 * Ideally, therefore, the parser would only need to parse one complete
	 * top-level block at a time, render it, and move on. Unfortunately, this
	 * is not possible with \parse_blocks() because it must parse the
	 * entire given document at once.
	 *
	 * While the current implementation prevents this optimization, it’s still
	 * possible to reduce the peak memory use when calls to `render_block()`
	 * on those top-level blocks are memory-heavy (which many of them are).
	 * By setting each parsed block to `NULL` after rendering it, any memory
	 * allocated during the render will be freed and reused for the next block.
	 * Before making this change, that memory was retained and would lead to
	 * out-of-memory crashes for certain posts that now run with this change.
	 */
	for ( $i = 0; $i < $top_level_block_count; $i++ ) {
		$output      .= render_block( $blocks[ $i ] );
		$blocks[ $i ] = null;
	}

	// If there are blocks in this content, we shouldn't run wpautop() on it later.
	$priority = has_filter( 'the_content', 'wpautop' );
	if ( false !== $priority && doing_filter( 'the_content' ) && has_blocks( $content ) ) {
		remove_filter( 'the_content', 'wpautop', $priority );
		add_filter( 'the_content', '_restore_wpautop_hook', $priority + 1 );
	}

	return $output;
}
```

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

- 5.0.0 — Introduced.

## Связанные

Использует: [`parse_blocks`](https://chugunov.pro/api-wordpress/functions/parse_blocks/), [`render_block`](https://chugunov.pro/api-wordpress/functions/render_block/), [`has_blocks`](https://chugunov.pro/api-wordpress/functions/has_blocks/), [`has_filter`](https://chugunov.pro/api-wordpress/functions/has_filter/), [`doing_filter`](https://chugunov.pro/api-wordpress/functions/doing_filter/), [`remove_filter`](https://chugunov.pro/api-wordpress/functions/remove_filter/), [`add_filter`](https://chugunov.pro/api-wordpress/functions/add_filter/).
Используется в: [`block_template_part`](https://chugunov.pro/api-wordpress/functions/block_template_part/), [`get_the_block_template_html`](https://chugunov.pro/api-wordpress/functions/get_the_block_template_html/).

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