For some reason I cannot output the color. Everything works, but text_color
just doesn’t want to output its value.
What is going wrong?
Back end code (functions.php):
$wp_customize->add_setting('text_color', array(
'default' => '#fff',
'sanitize_callback' => 'sanitize_hex_color',
'type' => 'option',
));
$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'text_color', array(
'label' => __('Text color', 'pc'),
'section' => 'colors',
'settings' => 'text_color',
)));
Front end code:
if(!empty(get_theme_mod( 'text_color' ))) {
?>
h1, h2, h3, h4, h5, h6 {
color:<?php echo get_theme_mod( 'text_color' ); ?>
}
<?php
}
3 Answers
The 'type'=>'option'
parameter is not required for the colour picker, instead use:
$wp_customize->add_setting('text_color', array(
'default' => '#fff',
'sanitize_callback' => 'sanitize_hex_color',
));