0

I'm having an issue where the Customizer Preview doesn't seem to fully refresh, but if I manually refresh the page the changes work. I've made a simplified example of the issue I'm experiencing:

I have a simple checkbox in the Customizer:

$wp_customize->add_setting(
    'test_checkbox',
        array(
            'default'     => false,
    )
);

$wp_customize->add_control(
    new WP_Customize_Control(
        $wp_customize,
        'test',
        array(
            'label'      => 'Checkbox',
            'section'    => 'test_section',
            'settings'   => 'test_checkbox',
            'type'       => 'checkbox',
        )
    )
);

In my functions.php file I have an if statement that checks if the checkbox is checked and if it is, I create a function:

if(get_theme_mod('test_checkbox', false) == true) {
    function test_function() {
        return 'SUCCESS';
    }
}

In my index.php file I check if the function exists and echo it

if(function_exists('test_function')) {
    echo test_function();
}

Now when I go to the Customizer and check the checkbox, the Preview refreshes but I don't see the Success message. I have to manually refresh the page before I see it.

Does anyone know why this happens?

Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.