pre_render_block
Allows render_block() to be short-circuited, by returning a non-null value.
Usage
add_filter( 'pre_render_block', 'wp_kama_pre_render_block_filter', 10, 3 ); /** * Function for `pre_render_block` filter-hook. * * @param string|null $pre_render The pre-rendered content. * @param array $parsed_block An associative array of the block being rendered. See WP_Block_Parser_Block. * @param WP_Block|null $parent_block If this is a nested block, a reference to the parent block. * * @return string|null */ function wp_kama_pre_render_block_filter( $pre_render, $parsed_block, $parent_block ){ // filter... return $pre_render; }
- $pre_render(string|null)
- The pre-rendered content.
Default: null - $parsed_block(array)
An associative array of the block being rendered. See WP_Block_Parser_Block.
-
blockName(string)
Name of block. -
attrs(array)
Attributes from block comment delimiters. -
innerBlocks(array[])
List of inner blocks. An array of arrays that have the same structure as this one. -
innerHTML(string)
HTML from inside block comment delimiters. - innerContent(array)
List of string fragments and null markers where inner blocks were found.
-
- $parent_block(WP_Block|null)
- If this is a nested block, a reference to the parent block.
Changelog
Since 5.1.0 | Introduced. |
Since 5.9.0 | The $parent_block parameter was added. |
Where the hook is called
pre_render_block
wp-includes/blocks.php 2263
$pre_render = apply_filters( 'pre_render_block', null, $parsed_block, $parent_block );
wp-includes/class-wp-block.php 542
$pre_render = apply_filters( 'pre_render_block', null, $inner_block->parsed_block, $parent_block );
Where the hook is used in WordPress
wp-includes/block-supports/settings.php 152
add_filter( 'pre_render_block', '_wp_add_block_level_preset_styles', 10, 2 );