Hi,
So I have just noticed quite a funny(not) thing with the WP_Customize_Color_Control.
Let's say I have this code:
$wp_customize->add_setting(
'theme_color_link',
array(
'default' => '#26bcd7',
'sanitize_callback' => 'sanitize_hex_color',
)
);
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
'theme_color_link',
array(
'label' => 'Main body link color',
'section' => 'colors',
'settings' => 'theme_color_link',
'priority' => 2,
)
)
);
When I go to Appearance > Customize, I see the default value, everything is OK. If I change the color - everything is OK.
However, if I click "Save & Publish" then I'm somewhat stuck with this CSS element in the header. Whatever I choose in the color picker, I cannot "unset" this theme_mod value.
A similar thread is this one, but this actually happens no matter if there is a defined default value or not.
Using this function (from Codex):
function generate_css( $selector, $style, $mod_name, $prefix='', $postfix='', $echo=true ) {
$return = '';
$mod = get_theme_mod($mod_name);
if ( ! empty( $mod )) {
$return = sprintf('%s { %s: %s; }
',
$selector,
$style,
$prefix.$mod.$postfix
);
if ( $echo ) {
echo $return;
}
}
return $return;
}
So I guess the question is: how do I stop this function from adding the CSS rules in my header, when there is no value or the value is the default one?
Having redundant inline CSS doesn't feel right.
Thanks.