Skip to content

Instantly share code, notes, and snippets.

@vajrasar
Created March 6, 2018 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vajrasar/f1091d80870b305eb4518c4a7ca69ff6 to your computer and use it in GitHub Desktop.
Save vajrasar/f1091d80870b305eb4518c4a7ca69ff6 to your computer and use it in GitHub Desktop.
+ Remove Default Color Menu from Theme Customizer. + Add a Primary Site Color element in Site Identity menu of the Theme Customizer. + Apply Color based on selection on the Primary Site Color option from the customizer
<?php
//Add Primary Color option in Site Identity and Remove default Colors menu
function your_theme_new_primary_color_settings($wp_customize) {
$wp_customize->remove_section( 'colors');
$wp_customize->add_setting('your_color');
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
'your_color',
array(
'label' => 'Primary Site Color',
'section' => 'title_tagline',
'settings' => 'your_color',
) )
);
}
add_action('customize_register', 'your_theme_new_primary_color_settings');
//Apply Colors on site locations as per the Primary Color selection
function wptutsplus_customize_colors() {
$thecolor = get_theme_mod( 'your_color' );
?>
<style type="text/css">
.site-title a {
color: <?php echo $thecolor; ?> !important;
}
button, input[type="button"], input[type="reset"], input[type="submit"], .button {
background-color: <?php echo $thecolor; ?> !important;
}
.home-featured-2,
.calltoaction-container {
background-color: <?php echo $thecolor; ?> !important;
}
a.button._mPS2id-h {
background-color: <?php echo $thecolor; ?> !important;
background-image: none;
}
</style>
<?php
}
add_action( 'wp_head', 'wptutsplus_customize_colors' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment