Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

get_theme_mod default values not showing.

In wordpress customizer, I have created settings and added default values to them. They do not show up but when i visit the customizer page I see the default values being applied. Also they do not show up on the front page unless i add custom values to them first.

1 Answer

Jacobus Hindson
Jacobus Hindson
14,429 Points

I am not expert of the Customizer, just learning myself but are you calling your Settings via css like:

.footer {
     border-top: solid 1px #<?php echo get_theme_mod( 'background_color' ); ?>;
}

No Jacobus. (and also sorry for no asking the question well) I was asking about declaring default values when creating a "setting and control".

I realized that the default values when creating the settings and controls will not show up unless the user first add a custom value. for example this default value which is "#cfcfcf" will not show up

<?php
    $wp_customize->add_setting(
    'background_color',
    array(
        'default' => '#cfcfcf',
        'transport'         => 'postMessage',
        'sanitize_callback' => 'sanitize_hex_color',
    ));

    $wp_customize->add_control(
        new WP_Customize_Color_Control(
            $wp_customize,
            'background_color',
            array(
                'label' => 'Overlay Color',
                'description' => 'Change background color',
                'section' => 'about_section',
                'settings' => 'background_color',
            )));
?>

But I have been able to work around it. I just have to re-declare the default value again in get_theme_mod like this

.footer {
     border-top: solid 1px #<?php echo get_theme_mod( ' background_color ' ,  ' #cfcfcf ' ); ?>;
}

this one works perfect.

Jacobus Hindson
Jacobus Hindson
14,429 Points

Well glad it has all worked out for you.