apply_filters( 'render_block', string $block_content , array $block , WP_Block $instance )
Filters the content of a single block.
Parameters
-
$block_content
string -
The block content.
-
$block
array -
The full block, including name and attributes.
-
$instance
WP_Block -
The block instance.
Source
File: wp-includes/class-wp-block.php
.
View all references
$block_content = apply_filters( 'render_block', $block_content, $this->parsed_block, $this );
Changelog
Version | Description |
---|---|
5.9.0 | The $instance parameter was added. |
5.0.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
To add a div wrapper outside of some blocks (like
core/paragraph
orcore/heading
), you can add filter torender_block
:Top ↑
Feedback
This doesn’t work anymore I’m afraid as all core blocks have their `blockName` set to null for some obscure reason :( https://github.com/WordPress/WordPress/blob/master/wp-includes/blocks.php#L697 — By petrey —
$block
(array) The full block, including name and attributes.
Good to know that
$block['attrs']
do not include attributes declared in block.json with “source” set to “attribute”.For example, in a block.json :
$block['attrs']
only includewidth
, noturl
.Here’s a quick/rough example of how you can render any block in any way with this filter. Note that the example uses an attribute called `name_of_attribute_here`. You’ll want to use an actual attribute that belongs to that block.
A quick/easy way to discover what’s available to you is to `print_r( $block );` inside the function, refresh the frontend page where the block sits, and see what’s available in the `attrs`.