Skip to content

Instantly share code, notes, and snippets.

@ajskelton
Last active August 23, 2022 15:59
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save ajskelton/740788f98df3283355dd7e0c2f5abb2a to your computer and use it in GitHub Desktop.
Save ajskelton/740788f98df3283355dd7e0c2f5abb2a 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