Is there a way to set the gutenberg color palette outside the theme?

Is there a away to set the gutenberg block-editor color palette other than in the theme?

Topic block-editor color-picker Wordpress

Category Web


Yes, you have to use the init hook if you want to use add_theme_support from a plugin. I've tested the below code as a plugin and worked for me.

<?php

/* Plugin name: Add Color Palette
*/
function mytheme_setup_theme_supported_features()
{
    add_theme_support('editor-color-palette', array(
        array(
            'name' => esc_attr__('Strong magenta', 'themeLangDomain'),
            'slug' => 'strong-magenta',
            'color' => '#a156b4',
        ),
    ));
}

add_action('init', 'mytheme_setup_theme_supported_features');

Please consider avoiding using add_theme_support outside the theme's functions.php file.

The official description for the add_theme_support :

Must be called in the theme’s functions.php file to work. If attached to a hook, it must be ‘after_setup_theme’. The ‘init’ hook may be too late for some features.

https://developer.wordpress.org/reference/functions/add_theme_support/

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.