Customizer: Output default value in Customizer CSS

I’ve seen the code below in the WordPress Theme Customization API and several themes to output Customizer CSS in the head. It works great but I’m wondering if it can be modified to display a default value, if no value is given for header_textcolor, background_color or link_textcolor.

public static function header_output() {
?>
<!–Customizer CSS–>
<style type=”text/css”>
<?php self::generate_css(‘#site-title a’, ‘color’, ‘header_textcolor’, ‘#’); ?>
<?php self::generate_css(‘body’, ‘background-color’, ‘background_color’, ‘#’); ?>
<?php self::generate_css(‘a’, ‘color’, ‘link_textcolor’); ?>
</style>
<!–/Customizer CSS–>
<?php
}

public static 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;
}

Read more here:: Customizer: Output default value in Customizer CSS

Leave a Reply

Your email address will not be published. Required fields are marked *