In WP 6.3 there's the native "group", but if you want to set something for it globally, you can't really override it or something.
Create a simple container
class parent block
I've tested these codes exactly and you will have a container block in the end :-) (WordPress 6.3.1)
Codes are as simple as possible and there will be ALL parts you need.
If you just care about the JS part - see the end of this answer :-)
Note: JS is still required for this to work (no block.json option yet :( ), but you can use plain JS :-)
Ref docs: WP documentation for "Nested Blocks: Using InnerBlocks" - choose Plain
yourtheme/blocks/container/block.json
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "yourtheme/container",
"title": "Container",
"description": "Wrap elements",
"style": [],
"category": "text",
"icon": "format-aside",
"keywords": ["container"],
"render": "file:./render.php"
}
yourtheme/blocks/container/render.php
<?php
/**
* Your Container - block template
*
* @param WP_Block $block The block settings and attributes.
*/
declare(strict_types=1);
if (!defined('ABSPATH')) {
exit();
}
?>
<div class="container">
<?php
/** @var WP_Block $block */
echo $block->render(['dynamic' => false]);
?>
</div>
<?php
The JS part - yourtheme/functions.php
Ideally you want to save this to a separate JS file and do standard enqueuing, but this is the quick way out...
add_action('admin_head', function () {
?>
<script>
( function ( blocks, element, blockEditor ) {
const el = element.createElement;
const InnerBlocks = blockEditor.InnerBlocks;
const useBlockProps = blockEditor.useBlockProps;
blocks.registerBlockType( 'yourtheme/container', {
edit: function () {
let blockProps = useBlockProps();
// override all classes to just "container" (you can append if you want...)
blockProps.className = 'container';
return el( 'div', blockProps, el( InnerBlocks ) );
},
save: function () {
let blockProps = useBlockProps.save();
return el( InnerBlocks.Content );
},
} );
} )( window.wp.blocks, window.wp.element, window.wp.blockEditor );
</script>
<?php
});