Last active
May 14, 2024 04:54
-
-
Save ajskelton/740788f98df3283355dd7e0c2f5abb2a to your computer and use it in GitHub Desktop.
Add a Checkbox field to the WordPress Customizer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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