Is there a away to set the gutenberg block-editor color palette other than in the theme?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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/
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0