# excerpt_remove_blocks()

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

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

## Сигнатура

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

## Описание

Поскольку отрывок должен быть небольшим фрагментом текста, отражающим полное содержимое записи, эта функция отображает блоки, которые с наибольшей вероятностью содержат такой текст.

## Параметры

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

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

`string`

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

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

```php
function excerpt_remove_blocks( $content ) {
	if ( ! has_blocks( $content ) ) {
		return $content;
	}

	$allowed_inner_blocks = array(
		// Classic blocks have their blockName set to null.
		null,
		'core/freeform',
		'core/heading',
		'core/html',
		'core/list',
		'core/media-text',
		'core/paragraph',
		'core/preformatted',
		'core/pullquote',
		'core/quote',
		'core/table',
		'core/verse',
	);

	$allowed_wrapper_blocks = array(
		'core/columns',
		'core/column',
		'core/group',
	);

	/**
	 * Filters the list of blocks that can be used as wrapper blocks, allowing
	 * excerpts to be generated from the `innerBlocks` of these wrappers.
	 *
	 * @since 5.8.0
	 *
	 * @param string[] $allowed_wrapper_blocks The list of names of allowed wrapper blocks.
	 */
	$allowed_wrapper_blocks = apply_filters( 'excerpt_allowed_wrapper_blocks', $allowed_wrapper_blocks );

	$allowed_blocks = array_merge( $allowed_inner_blocks, $allowed_wrapper_blocks );

	/**
	 * Filters the list of blocks that can contribute to the excerpt.
	 *
	 * If a dynamic block is added to this list, it must not generate another
	 * excerpt, as this will cause an infinite loop to occur.
	 *
	 * @since 5.0.0
	 *
	 * @param string[] $allowed_blocks The list of names of allowed blocks.
	 */
	$allowed_blocks = apply_filters( 'excerpt_allowed_blocks', $allowed_blocks );
	$blocks         = parse_blocks( $content );
	$output         = '';

	foreach ( $blocks as $block ) {
		if ( in_array( $block['blockName'], $allowed_blocks, true ) ) {
			if ( ! empty( $block['innerBlocks'] ) ) {
				if ( in_array( $block['blockName'], $allowed_wrapper_blocks, true ) ) {
					$output .= _excerpt_render_inner_blocks( $block, $allowed_blocks );
					continue;
				}

				// Skip the block if it has disallowed or nested inner blocks.
				foreach ( $block['innerBlocks'] as $inner_block ) {
					if (
						! in_array( $inner_block['blockName'], $allowed_inner_blocks, true ) ||
						! empty( $inner_block['innerBlocks'] )
					) {
						continue 2;
					}
				}
			}

			$output .= render_block( $block );
		}
	}

	return $output;
}
```

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

- 5.0.0 — Introduced.

## Связанные

Использует: [`_excerpt_render_inner_blocks`](https://chugunov.pro/api-wordpress/functions/_excerpt_render_inner_blocks/), [`parse_blocks`](https://chugunov.pro/api-wordpress/functions/parse_blocks/), [`has_blocks`](https://chugunov.pro/api-wordpress/functions/has_blocks/), [`render_block`](https://chugunov.pro/api-wordpress/functions/render_block/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: [`wp_trim_excerpt`](https://chugunov.pro/api-wordpress/functions/wp_trim_excerpt/).

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