# Restrict Button Block Colors to Brand Colors

> Gives the Button block its own small palette of brand colors and removes the custom color picker for it, so every button on the site stays on-brand.

- Type: PHP
- Runs: Run everywhere
- Category: [Block Editor](https://wpide.com/library/category/gutenberg/)
- Tags: theme-json, buttons, colors
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/themejson-button-palette/

## Code

```php
// Colors allowed for buttons: slug => [name, hex].
$wpide_button_colors = array(
    'wpide-btn-primary'   => array( 'Primary', '#1d4ed8' ),
    'wpide-btn-secondary' => array( 'Secondary', '#111827' ),
    'wpide-btn-light'     => array( 'Light', '#ffffff' ),
);

add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) use ( $wpide_button_colors ) {
    $palette = array();

    foreach ( $wpide_button_colors as $slug => $color ) {
        $palette[] = array( 'slug' => $slug, 'name' => $color[0], 'color' => $color[1] );
    }

    return $theme_json->update_with( array(
        'version'  => WP_Theme_JSON::LATEST_SCHEMA,
        'settings' => array(
            'blocks' => array(
                'core/button' => array(
                    'color' => array(
                        'palette'        => $palette,
                        'custom'         => false,
                        'customGradient' => false,
                        'defaultPalette' => false,
                    ),
                ),
            ),
        ),
    ) );
} );
```

## Notes

Other blocks keep the full theme palette.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Restrict Button Block Colors to Brand Colors" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
