Last active
January 10, 2020 00:52
-
-
Save ajskelton/544de9a67120434727db0652c7d44adf 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 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( '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