get_theme_mod not working

For some reason I cannot output the color. Everything works, but text_color just doesn't want to output its value.

What is going wrong?

Back end code (functions.php):

$wp_customize-add_setting('text_color', array(
    'default'           = '#fff',
    'sanitize_callback' = 'sanitize_hex_color',
    'type'           = 'option',
));

$wp_customize-add_control( new WP_Customize_Color_Control($wp_customize, 'text_color', array(
    'label'    = __('Text color', 'pc'),
    'section'  = 'colors',
    'settings' = 'text_color',
)));

Front end code:

if(!empty(get_theme_mod( 'text_color' ))) {
?
h1, h2, h3, h4, h5, h6 {
    color:?php echo get_theme_mod( 'text_color' ); ?
}
?php
}

Topic theme-customizer get-theme-mod Wordpress

Category Web


With

type => option

use

get_option( 'text_color' )

and

type => theme_mod (default)

use

get_theme_mod( 'text_color' )

More here: https://codex.wordpress.org/Class_Reference/WP_Customize_Manager/add_setting


if you are using this

add_setting('text_color'...

instead of

add_setting('themename_theme['text_color'] ....

you should retrieve data by

get_option('text_color');

The 'type'=>'option' parameter is not required for the colour picker, instead use:

$wp_customize->add_setting('text_color', array(
    'default'           => '#fff',
    'sanitize_callback' => 'sanitize_hex_color',
));

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.