apply_filters( “render_block_{$this->name}”, string $block_content, array $block, WP_Block $instance )

Filters the content of a single block.

Description

The dynamic portion of the hook name, $name, refers to the block name, e.g. "core/paragraph".

Parameters

$block_contentstring
The block content.
$blockarray
The full block, including name and attributes.
$instanceWP_Block
The block instance.

Source

$block_content = apply_filters( "render_block_{$this->name}", $block_content, $this->parsed_block, $this );

Changelog

VersionDescription
5.9.0The $instance parameter was added.
5.7.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    If you’ve arrived here wondering why your image block with Expand on Click enabled contains lightbox markup that you seemingly can’t access from inside your filter function, here’s some extra information you might need:

    As of WordPress 6.4, please be aware that a built-in filter for the image block has been applied with priority 15 for images with Expand on Click. This means that if your filter has a priority of 15 or lower (the default is 10), then the markup used to create the lightbox behavior will NOT be available to your function for processing by default.

    Please make sure to use priority of at least 16 when adding filters to process the image block if you need to access the lightbox markup:

    add_filter( 'render_block_core/image', 'wpdocs_custom_html', 16 )

    See this issue for more details.

  2. Skip to note 4 content

    $block is array with keys:

    • blockName
    • attrs – array of block attributes
    • innerBlocks – array of inner blocks
    • innerHTML – resultant HTML from inside block comment delimiters after removing inner blocks.
    • innerContent – list of string fragments and null markers where inner blocks were found

    These keys are explained and referenced in WP_Block

You must log in before being able to contribute a note or feedback.