Opened 5 months ago
#60544 new enhancement
Allow individual blocks to be excluded from `excerpt_remove_blocks()`
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.5 |
Component: | Formatting | Keywords: | needs-patch |
Focuses: | Cc: |
Description
In excerpt_remove_blocks()
, it is possible to to filter the list of block names that should be included when generating excerpt text.
It should also be possible to selectively exclude (or include) individual blocks based on their individual attributes.
For this to work, a new filter would need to be inserted in excerpt_remove_blocks()
and _excerpt_render_inner_blocks()
.
I think it would then be enough to check with the existing logic as:
if ( in_array( $block['blockName'], $allowed_blocks, true ) && apply_filters( 'excerpt_allowed_block', true, $block ) )
Then, if I added a custom attribute to a core (e.g. paragraph) block, I could add a filter to return false
when that attribute was detected.
The current alternative for this is unhooking wp_trim_excerpt()
from get_the_excerpt()
entirely and then reusing it as forked code with an alternate version of excerpt_remove_blocks()
.