Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WP Render Block Filter
/**
* @param $block_content
* @param $block
*
* @return string
Surrounds block with html.
* Some blocks are too naked to work nicely like ul
*/
function surround_block( $block_content, $block ) {
if ( empty( trim( $block_content ) ) ) {
return $block_content;
}
if($block['blockName'] == 'core/list'){
return sprintf(
'<div class="block-%1$s">%2$s</div>',
sanitize_title( $block['blockName'] ),
$block_content
);
}
return $block_content;
}
add_filter( 'render_block', 'surround_block', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.