apply_filters( 'render_block', string $block_content, array $block )

Filters the content of a single block.


Description Description


Parameters Parameters

$block_content

(string) The block content about to be appended.

$block

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


Top ↑

Source Source

File: wp-includes/blocks.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.


Top ↑

User Contributed Notes 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 );
    

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