-
-
Save Jespertastesen/b0ba004d9657ec0b2b379151bbd78c9e to your computer and use it in GitHub Desktop.
Add a Date field to the WordPress Customizer. Includes sanitize function for displaying date as '2016-10-25'.
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( 'date_setting_id', array( | |
'capability' => 'edit_theme_options', | |
'sanitize_callback' => 'themeslug_sanitize_date', | |
) ); | |
$wp_customize->add_control( 'date_setting_id', array( | |
'type' => 'date', | |
'section' => 'custom_section', // Add a default or your own section | |
'label' => __( 'Custom Date' ), | |
'description' => __( 'This is a custom date control.' ), | |
'input_attrs' => array( | |
'placeholder' => __( 'mm/dd/yyyy' ), | |
), | |
) ); | |
function themeslug_sanitize_date( $input ) { | |
$date = new DateTime( $input ); | |
return $date->format('m-d-Y'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment