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!


You can put condition while printing display's value

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

Your Answer

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

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