Skip to content

Instantly share code, notes, and snippets.

@Jespertastesen
Forked from ajskelton/WP Customizer - Date
Created May 27, 2017 16:13
Show Gist options
  • Save Jespertastesen/b0ba004d9657ec0b2b379151bbd78c9e to your computer and use it in GitHub Desktop.
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'.
$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