Skip to content

Instantly share code, notes, and snippets.

@anybodesign
Last active September 26, 2018 17:19
Show Gist options
  • Save anybodesign/7c93a708c49f6b127155755d82dbca28 to your computer and use it in GitHub Desktop.
Save anybodesign/7c93a708c49f6b127155755d82dbca28 to your computer and use it in GitHub Desktop.
Customizer custom colors for Gutenberg color palette
// Example of custom color defined in the Customizer
$wp_customize->add_setting('primary_color', array(
'default' => '99CC00',
'sanitize_callback' => 'sanitize_hex_color',
'capability' => 'edit_theme_options',
'type' => 'theme_mod',
'transport' => 'refresh',
));
$wp_customize->add_control( new WP_Customize_Color_control($wp_customize, 'primary_color_ctrl', array(
'label' => __('Primary color', 'your-textdomain'),
'section' => 'colors',
'settings' => 'primary_color',
)));
// Gutenberg Custom color palette
add_theme_support( 'editor-color-palette', array(
array(
'name' => esc_html__( 'Primary color', 'your-textdomain' ),
'slug' => 'primary-color',
'color' => get_theme_mod('primary_color', '#99CC00'),
),
array(
'name' => esc_html__( 'Secondary color', 'your-textdomain' ),
'slug' => 'secondary-color',
'color' => get_theme_mod('secondary_color', '#606060'),
),
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment