Proper way to get value from WordPress customize control

I’m currently woking on a WordPress Theme and trying to add a customize setting control. I have a functions.php where I add a setting and control like this:

//  =============================
//  = Radio Input               =
//  =============================
$wp_customize->add_setting('radio_input', array(
    'default'        => 'value2',
    'capability'     => 'edit_theme_options',
    'type'           => 'theme_mod',
));

$wp_customize->add_control('themename_color_scheme', array(
    'label'      => __('Radio Input', 'themename'),
    'section'    => 'themename_color_scheme',
    'settings'   => 'radio_input',
    'type'       => 'radio',
    'choices'    => array(
        'value1' => 'Choice 1',
        'value2' => 'Choice 2',
        'value3' => 'Choice 3',
    ),
));

and it works. I can choose the option in the Theme Customizer in WordPress.
Now I want to check in my main document, which choice is selected – but I don’t get any values back. Here is the code to echo the choices array.

 <?php 
    echo get_theme_mod('radio_input'); 
 ?>

And even if I change the setting type (Checkbox, Text Input, Dropdown) I never get any value back. If I echo a string (for testing purpose) I will see the string but I can’t get the values from the setting control. What am I doing wrong here?

Thank you in advance!

Read more here: Proper way to get value from WordPress customize control

Leave a Reply

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