• Resolved zagreus

    (@zagreus)


    Hi everyone

    I’m trying to add a couple of controls and use those in my child theme. I’ve successfully managed to add the controls, and I can use one of them in my template, however one of them always returns the default value because get_theme_mod returns null.

    Any help would be much appreciated.
    Here is where I add the settings and controls in the functions.php file:

    // Add Customizer settings
    function trd_customize_register($wp_customize) {
    
        // Accent Colour
        $wp_customize->add_setting('trd_theme_header_color', array(
            'default' => '#F16B20',
            'sanitize_callback' => 'sanitize_hex_color',
            'capability' => 'edit_theme_options',
            'type' => 'option',
        ));
    
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'trd_theme_header_color', array(
            'label' => __('Header Color', 'trd'),
            'description' => __('The highlight color will be used to color elements on automatic pages such as services, locations and classes.', 'trd'),
            'section' => 'fl-accent-color',
    //        'settings' => 'trd_theme_header_color',
        )));
    
        // Background Image
        $wp_customize->add_setting('trd_theme_header_background');
    
        $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'trd_theme_header_background', array(
            'label' => __('Header Background ', 'trd'),
            'description' => __('The background is shown on automatic posts from trd like locations, classes and services.', 'trd'),
            'section' => 'fl-accent-color',
            'settings' => 'trd_theme_header_background',
        )));
    }
    add_action('customize_register', 'trainerous_customize_register');

    Then here is where I add them to the head section. Note that the image part works, however the colour one is always NULL:

    // Embed styles in the heading
    function trd_customize_css() {
    
        $section_background = get_theme_mod('trd_theme_header_background');
        if ($section_background == '') { $section_background=FL_CHILD_THEME_URL . '/images/default-background-image.jpg';}
        
        $section_color = get_theme_mod('trd_theme_header_color', '#F16B20');
    
        ?>
        <style>
            .panel-default {
                background-image: url("<?= $section_background ?>");
            }
            .trdHeadlineHolder {
                background-color: <?= $section_color ?>;    
            }
        </style>
        <?php
    }
    
    add_action('wp_head', 'trd_customize_css');
    • This topic was modified 7 years, 6 months ago by zagreus.
    • This topic was modified 7 years, 6 months ago by zagreus.
Viewing 1 replies (of 1 total)
  • Thread Starter zagreus

    (@zagreus)

    For people following this, I found the problem. It’s because I marked the setting as type=>option. I was able to access the value when I removed this and it could default to theme_mod.

Viewing 1 replies (of 1 total)
  • The topic ‘Trouble with Customizer Variable’ is closed to new replies.