0

Heyo,

I'm once again stuck with my Customizer API. I want a Checkbox to set display:none on an div if it's checked. But insteat of picking the default value that I have set in the add_setting panel, it set's display:1.

my functions.php looks someting like this:

$wp_customize->add_setting('mytheme_setting', array(
    'default' => 'none',
    'transport' => 'refresh',
));

$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'mytheme_control', array(
    'label' => __('Display This!', 'mytheme'),
    'section' => 'mytheme_section',
    'settings' => 'mytheme_setting',
    'type' => 'checkbox',
)));

and the include looks something like this:

.someclass {
    display: <?php echo get_theme_mod('mytheme_setting'); ?>;
}

Now with this code, if the checkbox is checked it displays 'display:1' and if its not checked, it displays 'display:'. What am I missing?

Thanks in advance!

1 Answer 1

0

You can put condition while printing display's value

.someclass {
    display: <?php echo ( get_theme_mod( 'mytheme_setting' ) ? 'block' : 'none' ); ?>;
}
1
  • 1
    A checkbox control toggles a boolean value in the associated setting, so yes, this is the right approach. Commented Feb 15, 2017 at 18:10

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.