Skip to content

Instantly share code, notes, and snippets.

@ajskelton
Last active January 10, 2020 00:52
Show Gist options
  • Save ajskelton/544de9a67120434727db0652c7d44adf to your computer and use it in GitHub Desktop.
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'.
$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