Skip to content

Instantly share code, notes, and snippets.

@Yeadh
Forked from ajskelton/WP Customizer - Checkbox
Created September 23, 2017 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yeadh/9ae3742d718731921d1d61d31faa806f to your computer and use it in GitHub Desktop.
Save Yeadh/9ae3742d718731921d1d61d31faa806f 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