Skip to content

Instantly share code, notes, and snippets.

@seothemes
Last active April 16, 2019 15:06
Show Gist options
  • Save seothemes/e7b16502eec2843f00f1548421fec1ab to your computer and use it in GitHub Desktop.
Save seothemes/e7b16502eec2843f00f1548421fec1ab to your computer and use it in GitHub Desktop.
<?php
// Register settings and controls with the Customizer.
add_action( 'customize_register', 'seo_customizer_register' );
function seo_customizer_register() {
global $wp_customize;
global $seo_default_colors;
// Loop through each variable in the array
foreach($seo_default_colors as $key => $value) {
// Add setting for each variable
$wp_customize->add_setting( $key , array(
'default' => $value,
'sanitize_callback' => 'sanitize_hex_color',
) );
// Add control for each variable
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
$key,
array(
'label' => ucwords( str_replace( 'color-', '', $key ) ) . ' Color',
'section' => 'colors',
'settings' => $key,
) )
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment