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
$block_content = apply_filters( 'render_block', $block_content, $this->parsed_block, $this );
To add a div wrapper outside of some blocks (like
core/paragraph
orcore/heading
), you can add filter torender_block
:$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`.
$block_content
and$block
can becomenull
, so be sure to handle these cases.