[wp-trac] [WordPress Trac] #60544: Allow individual blocks to be excluded from `excerpt_remove_blocks()`

WordPress Trac noreply at wordpress.org
Wed Feb 14 23:16:54 UTC 2024


#60544: Allow individual blocks to be excluded from `excerpt_remove_blocks()`
-------------------------+-----------------------------
 Reporter:  jeremyfelt   |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Formatting   |    Version:  trunk
 Severity:  normal       |   Keywords:  needs-patch
  Focuses:               |
-------------------------+-----------------------------
 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()`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60544>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list