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_content string — Rendered block HTML.
  • $block array — 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

Group wizard

One session: this hook, then each related_hooks entry. Walk it and tell us what to change.

render_block → the_content

functions.php — render_block
functions.php
PHP render_block · Hook 1 of 2 · Step 1 of 6

Practice the render_block WordPress filter hook in our interactive sandbox — a VS Code-style editor with a step-by-step render_block tutorial, add_filter exercises, and instant feedback. No local WordPress install required.