Filter Hook since 5.0.0
render_block
Filters the final HTML output of every rendered block
Description
render_block runs for every block on the page, core and custom alike — check $block['blockName'] or it will touch content you didn't intend to change.
When it runs
Every time a block is rendered — on the front-end and anywhere do_blocks()/render_block() runs, including some REST responses.
Signature
apply_filters( 'render_block', string $block_content, array $block );Parameters
$block_contentstring — Rendered block HTML.$blockarray — Parsed block data, including blockName and attrs.
Examples
Basic
add_filter( 'render_block', function( $block_content, $block ) {
if ( 'core/image' !== $block['blockName'] ) {
return $block_content;
}
return str_replace( '<img', '<img loading="lazy"', $block_content );
}, 10, 2 );Add lazy-loading to a specific block type only.
Common Use Cases
- Modify markup of one specific block type
- Inject wrapper markup around blocks
- Add tracking attributes to CTA blocks
Common mistakes
- Not checking $block['blockName'] — the filter runs for every block on the page, so an unscoped change touches unrelated content
Related hooks
FAQ
Does render_block run for classic-editor content?
No — only for actual blocks. Classic editor HTML that isn't parsed into blocks goes through the_content filters instead.
Source: wp-includes/class-wp-block.php