To have a default value for get_theme_mod()
you can pass it as the 2nd argument, like this:
$mod = get_theme_mod( 'header_textcolor', '#000000' );
That will output #000000
if there isn’t a value saved for header_textcolor
.
Since your get_theme_mod()
call is getting the setting from another function, generate_css()
, you will need to update that function to also send a default:
public static function generate_css( $selector, $style, $mod_name, $default, $prefix='', $postfix='', $echo=true ) {
$return = '';
$mod = get_theme_mod( $mod_name, $default );
I’ve added it after $mod_name
in that example.
Then you would update your header_output()
function to include default values:
public static function header_output() {
?>
<!--Customizer CSS-->
<style type="text/css">
<?php self::generate_css('#site-title a', 'color', 'header_textcolor', '#000000', '#'); ?>
<?php self::generate_css('body', 'background-color', 'background_color', '#FFFFFF', '#'); ?>
<?php self::generate_css('a', 'color', 'link_textcolor', '#0000FF' ); ?>
</style>
<!--/Customizer CSS-->
<?php
}
Now there are default values for those colours.
I think it’s worth pointing out though, that your code will not output any CSS if the theme mod doesn’t have a value. This means that the default styles will come from your stylesheet. So I’m not sure having defaults here is necessary.