apply_filters( ‘render_block_data’, array $parsed_block, array $source_block, WP_Block|null $parent_block )

Filters the block being rendered in render_block() , before it’s processed.

Parameters

$parsed_blockarray
The block being rendered.
$source_blockarray
An un-modified copy of $parsed_block, as it appeared in the source content.
$parent_blockWP_Block|null
If this is a nested block, a reference to the parent block.

Source

$parsed_block = apply_filters( 'render_block_data', $parsed_block, $source_block, $parent_block );

Changelog

VersionDescription
5.9.0The $parent_block parameter was added.
5.1.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    Filter post content block and add custom classes for every post content block wrapper dynamically before render on template.

    /**
     * Filters the parsed block being rendered in render_block(), before it's processed.
     *
     * @param array  $parsed_block The block being rendered.
     * @return array $parsed_block Modified block.
     */
    function wpdocs_modify_render_block_data( $parsed_block ) {
    
        // Do check first its Post Content block or not.
        if ( ! empty( $parsed_block['blockName'] ) && 'core/post-content' === $parsed_block['blockName'] ) {
            $block_attributes = $parsed_block['attrs'];
    
            // Set custom class for post content block.
            $post_content_classe           = 'wpdocs-content-wrap';
            $block_attributes['className'] = $post_content_classe;
            
            $parsed_block['attrs'] = $block_attributes;
        }
    
        return $parsed_block;
    }
    add_filter( 'render_block_data', 'wpdocs_modify_render_block_data' );
  2. Skip to note 4 content

    Here is the structure of the $parsed_block

    $parsed_block = array(
        'blockName' => 'dragblock/link',
        'attrs' => array(),
    
        // child
        'innerBlocks' => array(
            array(
                'blockName' => 'dragblock/text',
                'attrs' => array(),
                'innerBlocks' => array(),
                'innerHTML' => '<span class="wp-block-dragblock-text"></span>',
                'innerContent' => array(
                    '<span class="wp-block-dragblock-text"></span>'
                )
            )
        ),
    
        // your current block output html without child blocks
        'innerHTML' => '<a class="wp-block-dragblock-link"></a>', 
    
        // your current block output html items without child blocks
        'innerContent' => array(
            '<a class="wp-block-dragblock-link">',
            null,
            '</a>'
        )
    );

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