I use your code like this
add_filter( 'render_block', function( $block_content, $block ) {
if (
!is_admin()
&& is_single()
&& ! empty( $block['attrs']['className'] )
&& 'post-summary' === $block['attrs']['className']
&& $summary
) {
$block_content = wp_trim_words( $block_content, 40 );
}
return $block_content;
}, 10, 2 );
and the additional css class for the content block is ‘post-summary’. But it’s not working. Maybe I should use CSS only to solve this?