Ok so I don’t feel very good about this solution, but – using the render_block hook:
- conditional to find the custom block
- set the $block_content variable=””; to clear it (or if you want to nest something inside tags, you can try to explode $block_content)
- loop through each child block and pull out the innerHTML, append to the $block_content variable and return that
function gss_block_wrapper($block_content, $block)
{
if ($block['blockName'] === 'create-block/gutenberg-swiper-slider') {
$block_content="";
foreach ($block['innerBlocks'] as $innerblock) {
$innerHTML = $innerblock['innerHTML'];
//innerHTML of each child block
$content="<div class="swiper-slide">" . $innerHTML . '</div>';
$block_content .= $content;
}
}
return $block_content;
}
add_filter('render_block', 'gss_block_wrapper', 10, 2);
Maybe I’m just not doing gutenberg right, but it feels like the InnerBlocks component could do with a built-in way to wrap child blocks.