
In this tutorial, I will be showing you how to add checkbox field to WordPress customizer.
I have discussed about the parameters for add_setting() and add_control() functions in my previous tutorial.
First lets create settings for checkbox field
$wp_customize->add_setting('themeslug_checkbox_id', array(
'default' => 'Select Checkbox',
));
then we create control for checkbox field
$wp_customize->add_control('themeslug_checkbox_id', array(
'label' => esc_html__('Input Type checkbox', 'themeslug'),
'type' => 'checkbox',
'priority' => 3,
'section' => 'themeslug_section_id',
'setting' => 'themeslug_checkbox_id',
'capability' => 'edit_theme_options',
));
Usage
<?php esc_html_e( get_theme_mod( 'themeslug_checkbox_id' ) ); ?>