apply_filters( 'relevanssi_rendered_block', string $content, array $block )

Filters Gutenberg blocks after they are rendered.


(string) The rendered block content from render_block().

(array) The block array.

More information

When Relevanssi indexes Gutenberg content, the post is split into blocks with parse_blocks() and then each block is rendered with render_block().

This filter hook gets the block content as it’s passed from render_block() and before Relevanssi sees it. This filter hook is the perfect choice if you do want to index a block, but you want to modify the block content somehow before Relevanssi sees it.

add_filter( 'relevanssi_rendered_block', 'rlv_modify_block_content', 10, 2 );
function rlv_modify_block_content( $content, $block ) {
  if ( 'custom/blockname' === $block['blockName'] ) {
    $content = str_replace( 'foo', 'bar', $content );
  return $content;

To modify the blocks before they are rendered (for example to exclude certain blocks from being indexed), you can use the relevanssi_block_to_render filter hook which gets the block after render_block().