解析内容字符串中的块,并呈现适合摘录的内容。

原型

excerpt_remove_blocks( string $content )

描述

由于摘录应该是与完整帖子内容相关的一小段文本,因此该函数会呈现最有可能包含此类文本的块。

参数

$content (string) (Required) 要解析的内容。

返回值

(string)  解析和过滤的内容。

源文件

路径:wp-includes/blocks.php

<?php
...
function excerpt_remove_blocks( $content ) {
	$allowed_blocks = array(
		// Classic blocks have their blockName set to null.
		null,
		'core/columns',
		'core/freeform',
		'core/heading',
		'core/html',
		'core/list',
		'core/media-text',
		'core/paragraph',
		'core/preformatted',
		'core/pullquote',
		'core/quote',
		'core/table',
		'core/verse',
	);
	/**
	 * 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 4.4.0
	 *
	 * @param array $allowed_blocks The list 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 ) ) {
			$output .= render_block( $block );
		}
	}
	 return $output;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/excerpt_remove_blocks/