Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress: Add aligncenter to Gutenberg groups block

Per default, the Gutenberg groups block has only two alignment options: wide and full width.

I now want to add a custom alignment center to the block. Other blocks like images have this option.

Is there any way to extend a core block like this?

I know that there is an option for custom styles with registerBlockStyle (See docs).

But is there also something like this for basic controls/settings? I couldn't find anything in the docs.

like image 728
Cray Avatar asked Nov 18 '25 05:11

Cray


1 Answers

I found an answer here.

It works, if I change the code like this:

wp.hooks.addFilter( 'blocks.registerBlockType',
  'my/change_alignment', ( settings, name ) => {

  switch( name ) {
    case 'core/group':
    case 'core/cover':
      return lodash.assign( {}, settings, {
        supports: lodash.assign( {}, settings.supports, {
          align: [ 'center', 'wide', 'full']
        } ),
      } );
  }

  return settings;
});
like image 145
Cray Avatar answered Nov 19 '25 19:11

Cray