Skip to content

Instantly share code, notes, and snippets.

@Asikur22
Forked from ajskelton/WP Customizer - Checkbox
Created September 1, 2019 04:31
Show Gist options
  • Save Asikur22/38eb5cafc0bc4e7179e4b190335a968b to your computer and use it in GitHub Desktop.
Save Asikur22/38eb5cafc0bc4e7179e4b190335a968b to your computer and use it in GitHub Desktop.
Add a Checkbox field to the WordPress Customizer.
$wp_customize->add_setting( 'themecheck_checkbox_setting_id', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'themeslug_sanitize_checkbox',
) );
$wp_customize->add_control( 'themeslug_checkbox_setting_id', array(
'type' => 'checkbox',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Checkbox' ),
'description' => __( 'This is a custom checkbox input.' ),
) );
function themeslug_sanitize_checkbox( $checked ) {
// Boolean check.
return ( ( isset( $checked ) && true == $checked ) ? true : false );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment