get_theme_mod only returns false
I have created a custom section with a setting with one control allowing users to choose fonts from a dropdown. However, when I use the get_theme_mod() function, and echo the results to a styles tag in the header, I get nothing.
The debugger tells me that get_theme_mod() is returning 'false', when I expect it to return the value of the selected item. Using get_option() gives me the key of the option, "value3" and not the value.
I would prefer to use get_theme_mod() since that is what the function is for, but if I can't how do I get it to output 'American Typewriter' instead of "value3"?
functions.php
function lettra_customized_css()
{
?
style type='text/css'
.site-title {
?php
$foo = get_option('title_font'); // "value3"
$bar = get_theme_mod('title_font');// false
?font-family: ?php echo get_theme_mod('title_font') ?;
}
/style
?php
}
add_action('wp_head', 'lettra_customized_css');
cutomizer.php
function lettra_customize_register($wp_customize)
{
$wp_customize-add_section(
'font_options',
array(
'title' = __('Font Options', 'lettra'), //Visible title of section
'priority' = 20, //Determines what order this appears in
'capability' = 'edit_theme_options', //Capability needed to tweak
'description' = __('Choose font pairings for your theme here.', 'lettra'), //Descriptive tooltip
)
);
$wp_customize-add_setting('title_font', array(
'default' = 'Roboto Slab',
'capability' = 'edit_theme_options',
'type' = 'option',
'transport' = 'postMessage'
));
$wp_customize-add_control('title_font_control', array(
'label' = __('Title Font', 'lettra'),
'section' = 'font_options',
'settings' = 'title_font',
'type' = 'select',
'choices' = array(
'value1' = 'Roboto Slab',
'value2' = 'Times New Roman',
'value3' = 'American Typewriter',
),
));
}
add_action('customize_register', 'lettra_customize_register');
Topic theme-customizer get-theme-mod options Wordpress
Category Web