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 about to be appended.

$block

(array) The full block, including name and attributes.

$instance

(WP_Block) The block instance.


Top ↑

Source

File: wp-includes/class-wp-block.php

View on Trac



Top ↑

Changelog

Changelog
Version Description
5.9.0 The $instance parameter was added.
5.0.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Khoi Pro

    To add a div wrapper outside of some blocks (like core/paragraph or core/heading), you can add filter to render_block:

    // functions.php
    function wporg_block_wrapper( $block_content, $block ) {
    	if ( $block['blockName'] === 'core/paragraph' ) {
    		$content = '<div class="wp-block-paragraph">';
    		$content .= $block_content;
    		$content .= '</div>';
    		return $content;
    	} elseif ( $block['blockName'] === 'core/heading' ) {
    		$content = '<div class="wp-block-heading">';
    		$content .= $block_content;
    		$content .= '</div>';
    		return $content;
    	}
    	return $block_content;
    }
    
    add_filter( 'render_block', 'wporg_block_wrapper', 10, 2 );
    
  2. Skip to note 2 content
    Contributed by Marie Comet

    $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 :

    "attributes": {
        "url": {
            "type": "string",
            "source": "attribute",
            "selector": "a",
            "attribute": "href"
        },
        "width": {
            "type": "number"
        }
    }

    $block['attrs'] only include width, not url.

You must log in before being able to contribute a note or feedback.