Created
January 21, 2020 16:18
-
-
Save saltnpixels/7ed39ef0bb7001896b4ef5ae88d5f142 to your computer and use it in GitHub Desktop.
WP Render Block Filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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