# How register block styles

**URL:** https://discourse.roots.io/t/how-register-block-styles/25126
**Category:** sage
**Tags:** gutenberg, bud, sage10
**Created:** 2023-04-09T09:47:48Z
**Posts:** 5

## Post 1 by @aitor — 2023-04-09T09:47:48Z

In previous projects I register block styles with PHP this way

```
register_block_style(
    'core/group',
    [
        'name' => 'dark',
        'label' => __('Dark', 'sage'),
    ]
);
```

But it doesn’t work anymore in a new Sage project. How do you do it?

---

## Post 2 by @strarsis — 2023-04-09T16:56:59Z

You have to do this in an appropriate action hook (`init`) (and add to `setup.php`):

```
add_action('init', function () {
    if (!function_exists('register_block_style')) {
        return;
    }

    register_block_style(
        'core/group',
        [
            'name' => 'dark',
            'label' => __('Dark', 'sage'),
        ]
    );
});
```

The example also checks for the existence of the `register_block_style` method, for very old WordPress installations where Gutenberg was not available in core yet, but this is not really necessary anymore.

I am still not aware of a declarative approach for registering block styles (as in `theme.json` or by adding a file to specific directory), so this is currently the best practice approach.

:thinking: Maybe I should add an example for this to the Sage 10 FSE theme ([GitHub - strarsis/sage10-fse: Sage 10 theme adjusted for Gutenberg Full Site Editing (FSE)](https://github.com/strarsis/sage10-fse)).

---

## Post 3 by @thunderdw — 2023-04-10T02:20:33Z

@strarsis Bud supports the file-based approach: [Styles | bud.js](https://bud.js.org/extensions/bud-preset-wordpress/editor-integration/styles)

---

## Post 4 by @strarsis — 2023-04-10T03:36:35Z

Well, I had not known that, great feature!

---

## Post 5 by @aitor — 2023-04-10T10:14:38Z

Thank you! I was unaware of that whole part of Bud’s integration with the editor.
