Last active
September 26, 2018 17:19
-
-
Save anybodesign/7c93a708c49f6b127155755d82dbca28 to your computer and use it in GitHub Desktop.
Customizer custom colors for Gutenberg color palette
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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