1

I am having a problem with the WordPress Customizer checkbox default value.

No matter what I put in the default value, but the checkbox is always checked in the theme customizer.

$wp_customize->add_setting( 'swastika_social_youtube', array(
    'capability' => 'edit_theme_options',
    'default'    =>  'false',
    'sanitize_callback' => 'swastika_sanitize_checkbox',
    ) 
);

$wp_customize->add_control( 'swastika_social_youtube', array(
    'type' => 'checkbox',
    'section' => 'social_settings_section', 
    'label'      => __( 'Show Youtube Icon', 'swastika' ),
    ) 
);

And here is how I am showing icon

<?php if ( true == get_theme_mod( 'swastika_social_youtube', false ) ) { ?> 
        <a href="#"><i class="fa fa-youtube-play" aria-hidden="true"></i></a>
    <?php } ?> 

enter image description here

Please Help Me

1 Answer 1

0

Your default of 'false' is actually a string, which evaluates to true because it's not empty. Use plain false, without the quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.