Issue with get_theme_mod returning a blank value instead of the saved value

I had the same issue.. using type=option and then get_option din’t work either.

Testing with another option item and works.. and testing with MYTHEMENAME_THEME_OPTION without the bracket for item and got an Array so I guess is the right way.

So just a tip for those who found this post but still got blank value.. when you use this code:

$wp_customize->add_setting('mytheme[mytext]', array(
    'default'        => 'some value you want default',
    'capability'     => 'edit_theme_options',
    'type'           => 'option',
));

$wp_customize->add_control('textControl', array(
    'label'      => __('LabelText', 'mytheme'),
    'section'    => 'parameters_thrive',
    'settings'   => 'mytheme[mytext]',  ));

then to get work you need to use each setting as a individual value,

$wp_customize->add_setting('mytext', array(
    'default'        => 'some value you want default',
    'capability'     => 'edit_theme_options',
    'type'           => 'option',
));

$wp_customize->add_control('textControl', array(
    'label'      => __('LabelText', 'mytheme'),
    'section'    => 'parameters_thrive',
    'settings'   => 'mytext',   ));

Where setting = myText, then is not more an array (before wasmytheme[mytext]) now is like a single item/value, a string. The go ahead and use the get_option() function to use the value whatever you want.

Leave a Comment