Skip to content

Instantly share code, notes, and snippets.

@asifpix
Forked from ajskelton/WP Customizer - Checkbox
Created September 10, 2017 06:19
Show Gist options
  • Save asifpix/8d2189997aafabccdbd63fb5436436ec to your computer and use it in GitHub Desktop.
Save asifpix/8d2189997aafabccdbd63fb5436436ec 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