render_block( array $parsed_block ): string
- Since
- 5.0.0
- Source
wp-includes/blocks.php:2336
Compatibility
- WordPress
- since 5.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$parsed_blockarray- An associative array of the block being rendered. See WP_Block_Parser_Block.
$blockNamestring|nullName of block.$attrsarrayAttributes from block comment delimiters.$innerBlocksarray[]List of inner blocks. An array of arrays that have the same structure as this one.$innerHTMLstringHTML from inside block comment delimiters.$innerContentarrayList of string fragments and null markers where inner blocks were found.
Return value
string- String of rendered HTML.
Performance profile
How much work a call to render_block() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 13–44
- Plugin surface
- 3 hooks
- Called by
- 5
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 45.
Third-party callbacks on 'pre_render_block', 'render_block_data', 'render_block_context' run inside this call, and their cost is not bounded by anything here.
5 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$pre_render !== null | 13 | apply_filters() |
$pre_render === null | 38–44 | apply_filters(), apply_filters(), apply_filters(), ->render() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 45 instructions, 13–44 executed per call, 2 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 3
3 hooks fire while render_block() runs, in this order:
- apply_filters( pre_render_block )filterline 2360 (+24 into the body)
Allows render_block() to be short-circuited, by returning a non-null value.
- apply_filters( render_block_data )filterline 2398 (+62 into the body)
Filters the block being rendered in render_block(), before it's processed.
- apply_filters( render_block_context )filterline 2434 (+98 into the body)
Filters the default context provided to a rendered block.
Uses · 2
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Block::__construct()Constructor.
Used by · 5
- WP_REST_Block_Renderer_Controller::get_item()Returns block output from block's registered render_callback.
- _excerpt_render_inner_blocks()Renders inner blocks from the allowed wrapper blocks for generating an excerpt.
- do_blocks()Parses dynamic blocks out of `post_content` and re-renders them.
- excerpt_remove_blocks()Parses blocks out of a content string, and renders those appropriate for the excerpt.
- twenty_twenty_one_print_first_instance_of_block()Prints the first instance of a block in the content, and then break away.
Source code
function render_block( $parsed_block ) { global $post; $parent_block = null; /** * Allows render_block() to be short-circuited, by returning a non-null value. * * @since 5.1.0 * @since 5.9.0 The `$parent_block` parameter was added. * * @param string|null $pre_render The pre-rendered content. Default null. * @param array $parsed_block { * An associative array of the block being rendered. See WP_Block_Parser_Block. * * @type string|null $blockName Name of block. * @type array $attrs Attributes from block comment delimiters. * @type array[] $innerBlocks List of inner blocks. An array of arrays that * have the same structure as this one. * @type string $innerHTML HTML from inside block comment delimiters. * @type array $innerContent List of string fragments and null markers where * inner blocks were found. * } * @param WP_Block|null $parent_block If this is a nested block, a reference to the parent block. */ $pre_render = apply_filters( 'pre_render_block', null, $parsed_block, $parent_block ); if ( ! is_null( $pre_render ) ) { return $pre_render; } $source_block = $parsed_block; /** * Filters the block being rendered in render_block(), before it's processed. * * @since 5.1.0 * @since 5.9.0 The `$parent_block` parameter was added. * * @param array $parsed_block { * An associative array of the block being rendered. See WP_Block_Parser_Block. * * @type string|null $blockName Name of block. * @type array $attrs Attributes from block comment delimiters. * @type array[] $innerBlocks List of inner blocks. An array of arrays that * have the same structure as this one. * @type string $innerHTML HTML from inside block comment delimiters. * @type array $innerContent List of string fragments and null markers where * inner blocks were found. * } * @param array $source_block { * An un-modified copy of `$parsed_block`, as it appeared in the source content. * See WP_Block_Parser_Block. * * @type string|null $blockName Name of block. * @type array $attrs Attributes from block comment delimiters. * @type array[] $innerBlocks List of inner blocks. An array of arrays that * have the same structure as this one. * @type string $innerHTML HTML from inside block comment delimiters. * @type array $innerContent List of string fragments and null markers where * inner blocks were found. * } * @param WP_Block|null $parent_block If this is a nested block, a reference to the parent block. */ $parsed_block = apply_filters( 'render_block_data', $parsed_block, $source_block, $parent_block ); $context = array(); if ( $post instanceof WP_Post ) { $context['postId'] = $post->ID; /* * The `postType` context is largely unnecessary server-side, since the ID * is usually sufficient on its own. That being said, since a block's * manifest is expected to be shared between the server and the client, * it should be included to consistently fulfill the expectation. */ $context['postType'] = $post->post_type; } /** * Filters the default context provided to a rendered block.Changelog
Introduced in 5.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/blocks.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.