简体   繁体   中英

WordPress: Add custom style to Gutenberg group block

I want to add some custom styles to the Gutenberg group block. Unfortunately the normal way doesn't work.

Here's my code for that (works for heading and other blocks):

wp.blocks.registerBlockStyle( 'core/group', {
    name: 'container',
    label: 'Container',
} );

Is there no option to add custom styles to this block? I saw that you can add custom colors and custom styles in the admin. So I don't understand why this wouldn't be possible.

I can't remember why my code didn't work. But now it does. Here's the full working code:

wp.domReady( () => {

    wp.blocks.registerBlockStyle(
        'core/group',
        [
            {
                name: 'container',
                label: 'Container',
            }
        ]
    );

} );

I guess the code was already correct and I haven't included it in the right way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM