The excerpt_allowed_wrapper_blocks WordPress PHP filter allows you to modify the list of blocks that can be used as wrapper blocks, enabling excerpts to be generated from the innerBlocks of these wrappers.
Usage
add_filter( 'excerpt_allowed_wrapper_blocks', 'my_custom_allowed_wrapper_blocks' ); function my_custom_allowed_wrapper_blocks( $allowed_wrapper_blocks ) { // your custom code here return $allowed_wrapper_blocks; } // Output: modified list of allowed wrapper blocks
Parameters
$allowed_wrapper_blocks
(string[]): The list of names of allowed wrapper blocks.
More information
See WordPress Developer Resources: excerpt_allowed_wrapper_blocks
Examples
Add a custom wrapper block to the allowed list
Add a custom wrapper block called my-theme/custom-wrapper
to the allowed list of wrapper blocks.
add_filter( 'excerpt_allowed_wrapper_blocks', 'add_custom_wrapper_block' ); function add_custom_wrapper_block( $allowed_wrapper_blocks ) { $allowed_wrapper_blocks[] = 'my-theme/custom-wrapper'; return $allowed_wrapper_blocks; } // Output: array with the 'my-theme/custom-wrapper' block added to the list
Remove a default allowed wrapper block
Remove the core/group
block from the list of allowed wrapper blocks.
add_filter( 'excerpt_allowed_wrapper_blocks', 'remove_group_wrapper_block' ); function remove_group_wrapper_block( $allowed_wrapper_blocks ) { $key = array_search( 'core/group', $allowed_wrapper_blocks ); if ( $key !== false ) { unset( $allowed_wrapper_blocks[$key] ); } return $allowed_wrapper_blocks; } // Output: array without the 'core/group' block
Replace the entire list of allowed wrapper blocks
Replace the default list of allowed wrapper blocks with a custom list.
add_filter( 'excerpt_allowed_wrapper_blocks', 'replace_allowed_wrapper_blocks' ); function replace_allowed_wrapper_blocks( $allowed_wrapper_blocks ) { return array( 'my-theme/custom-wrapper1', 'my-theme/custom-wrapper2' ); } // Output: array with only 'my-theme/custom-wrapper1' and 'my-theme/custom-wrapper2' blocks
Allow only specific wrapper blocks
Allow only specific wrapper blocks by creating a new allowed list.
add_filter( 'excerpt_allowed_wrapper_blocks', 'allow_specific_wrapper_blocks' ); function allow_specific_wrapper_blocks( $allowed_wrapper_blocks ) { return array( 'core/group', 'my-theme/custom-wrapper' ); } // Output: array with only 'core/group' and 'my-theme/custom-wrapper' blocks
Clear the list of allowed wrapper blocks
Clear the list of allowed wrapper blocks, disabling excerpts generation from any wrapper block.
add_filter( 'excerpt_allowed_wrapper_blocks', 'clear_allowed_wrapper_blocks' ); function clear_allowed_wrapper_blocks( $allowed_wrapper_blocks ) { return array(); } // Output: empty array