Since WordPress 6.0, you can define how content inside a group block is aligned. Besides the default, which does nothing, you can also display the content inline in a row or stack it. Together with the new layout options you can then justify the content and set its orientation based on your desires.

If you don’t want to use that feature, you can disable it. It’s basically both a block variation of the group block.

So you need to load a JavaScript file, that is executed once the DOM is ready to unregister these block variations:

wp.domReady( () => {
	wp.blocks.unregisterBlockVariation( 'core/group', 'group' );
	wp.blocks.unregisterBlockVariation( 'core/group', 'group-row' );
	wp.blocks.unregisterBlockVariation( 'core/group', 'group-stack' );
} );Code language: JavaScript (javascript)

Since the first one, group, is the default, you could let it registered. But since the button to select this block variation still shows up, I think it’s better to have it unregistered.

Group block variations with variations
Group block variations before unregister variations
Group block variations without variations
Group block variations after unregister variations

Let’s name the JavaScript file unregister-group-block-variations.js and place it inside your theme’s directory. Then open up your theme’s functions.php and add the following code to enqueue the JavaScript file:

/**
 * Enqueue editor assets.
 */
function my_editor_assets() {
	wp_enqueue_script( 'my-unregister-block-group-variations', get_template_directory_uri() . '/unregister-group-block-variations.js', [ 'wp-blocks', 'wp-editor' ], filemtime( get_template_directory() . '/unregister-group-block-variations.js' ), false );
}

add_action( 'enqueue_block_editor_assets', 'my_editor_assets' );Code language: PHP (php)

2 comments

  1. Thanks so much for posting this! It was exactly the thing I was looking for after not being able to figure this out on my own. As of WordPress 6.2 (most current version today), I think there may be an issue with this code now.

    Removing the “group” variation (first of the three unregistered in the snippet) leaves the Group block placeholder unusable because you can’t choose a layout to use (even though you don’t want people to have to choose!). It’s too bad that the group block placeholder seems to not pick up on the lack of variations. I tried overriding the default block variation to see if I could get it to skip the placeholder state but I couldn’t.

    So for now, I’m not unregistering the ‘group’ variation. If you know a solution, I’d love to hear it!

Leave a Reply

Your email address will not be published. Required fields are marked *