Skip to content

Instantly share code, notes, and snippets.

@saltnpixels
Created January 21, 2020 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saltnpixels/7ed39ef0bb7001896b4ef5ae88d5f142 to your computer and use it in GitHub Desktop.
Save saltnpixels/7ed39ef0bb7001896b4ef5ae88d5f142 to your computer and use it in GitHub Desktop.
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