Filter hook 'excerpt_allowed_blocks'

in WP Core File wp-includes/blocks.php at line 2157

View Source

excerpt_allowed_blocks

Filter Hook
Description
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.

Hook Information

File Location wp-includes/blocks.php View on GitHub
Hook Type Filter
Line Number 2157

Hook Parameters

Type Name Description
string[] $allowed_blocks The list of names of allowed blocks.

Usage Examples

Basic Usage
<?php
// Hook into excerpt_allowed_blocks
add_filter('excerpt_allowed_blocks', 'my_custom_filter', 10, 1);

function my_custom_filter($allowed_blocks) {
    // Your custom filtering logic here
    return $allowed_blocks;
}

Source Code Context

wp-includes/blocks.php:2157 - How this hook is used in WordPress core
<?php
2152  	 *
2153  	 * @since 5.0.0
2154  	 *
2155  	 * @param string[] $allowed_blocks The list of names of allowed blocks.
2156  	 */
2157  	$allowed_blocks = apply_filters( 'excerpt_allowed_blocks', $allowed_blocks );
2158  	$blocks         = parse_blocks( $content );
2159  	$output         = '';
2160  
2161  	foreach ( $blocks as $block ) {
2162  		if ( in_array( $block['blockName'], $allowed_blocks, true ) ) {

PHP Documentation

<?php
/**
	 * 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.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 1
  • File: wp-includes/blocks.php
Related Hooks

Related hooks will be displayed here in future updates.