-
-
Save Jespertastesen/e64297e63d2a99a6ca00b6ab9b6d39ce to your computer and use it in GitHub Desktop.
Add a Number field to the WordPress Customizer.
This file contains 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( 'themeslug_number_setting_id', array( | |
'capability' => 'edit_theme_options', | |
'sanitize_callback' => 'themeslug_sanitize_number_absint', | |
'default' => 1, | |
) ); | |
$wp_customize->add_control( 'themeslug_number_setting_id', array( | |
'type' => 'number', | |
'section' => 'custom_section', // Add a default or your own section | |
'label' => __( 'Custom Number' ), | |
'description' => __( 'This is a custom number.' ), | |
) ); | |
function themeslug_sanitize_number_absint( $number, $setting ) { | |
// Ensure $number is an absolute integer (whole number, zero or greater). | |
$number = absint( $number ); | |
// If the input is an absolute integer, return it; otherwise, return the default | |
return ( $number ? $number : $setting->default ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment