I can't figure out how to get the value - whether they are checked or not - from checkboxes in the WP customize manager.
This is the code in functions.php:
$wp_customize->add_setting('social_facebook', array(
'type' => 'option',
));
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'social_facebook',
array(
'label' => __( 'Facebook', 'theme_name' ),
'section' => 'social-icons',
'settings' => 'social_facebook',
'type' => 'checkbox',
)
)
);
And this is how I try to get the value:
<?php
$facebook = get_theme_mod('social_facebook');
if ($facebook != ''){?>
<style>
.facebook {display:inline!important;}
</style>
<?php }
?>
They values of the checkboxes are either "" (empty) or "1", so the system registers the checking of them. However, I don't know how to get the value through the get_theme_mod approach. Also, they don't have any name values, so I can't get the value through the usual way either.
$sticky_mod = get_theme_mod( 'wca_header_section_sticky' ) == '1' ? 'sticky' : '';
This is an example in my case - if that option is checked, it will echo a "sticky" class in my template.
if the setting 'my_theme_settings[social_facebook]' checkbox is unchecked:
<?php if( get_theme_mod( 'my_theme_settings[social_facebook]' ) == '') { ?>
//if setting is unchecked content here will be shown
<?php } // end if ?>
For full article see: http://themefoundation.com/wordpress-theme-customizer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With