Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



excerpt_remove_blocks ›

Seit5.0.0
Veraltetn/v
excerpt_remove_blocks ( $content )
Parameter:
  • (string) $content The content to parse.
    Erforderlich: Ja
Gibt zurück:
  • (string) The parsed and filtered content.
Definiert in:
Codex:

Parses blocks out of a content string, and renders those appropriate for the excerpt.

As the excerpt should be a small string of text relevant to the full post content, this function renders the blocks that are most likely to contain such text.



Quellcode

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;
}