I’m new to WordPress I want to add simple color picker in theme options.I tried but not getting can anyone suggest me?
3 Answers
Working code to set color customizer in wordpress theme settings:
function color_customizer($wp_customize){
$wp_customize->add_section( 'theme_colors_settings', array(
'title' => __( 'Theme Colors Settings', 'themeslug' ),
'priority' => 5,
) );
$theme_colors = array();
// Navigation Background Color
$theme_colors[] = array(
'slug'=>'color_section_name',
'default' => '#000000',
'label' => __('Color Section Title', 'themeslug')
);
foreach( $theme_colors as $color ) {
$wp_customize->add_setting(
$color['slug'], array(
'default' => $color['default'],
'sanitize_callback' => 'sanitize_hex_color',
'type' => 'option',
'capability' => 'edit_theme_options'
)
);
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
$color['slug'],
array('label' => $color['label'],
'section' => 'theme_colors_settings',
'settings' => $color['slug'])
)
);
}
}
add_action( 'customize_register', 'color_customizer' );