Skip to content

Instantly share code, notes, and snippets.

@ajskelton
Last active March 24, 2022 08:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ajskelton/ed556d7527d5314e01b367d91ddb50eb to your computer and use it in GitHub Desktop.
Save ajskelton/ed556d7527d5314e01b367d91ddb50eb to your computer and use it in GitHub Desktop.
Add a Time field to the WordPress Customizer. Includes sanitize function that formats the time as ('H:i')
$wp_customize->add_setting( 'themeslug_time_setting_id', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => '',
'default' => 1,
) );
$wp_customize->add_control( 'themeslug_time_setting_id', array(
'type' => 'time',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Time' ),
'description' => __( 'This is a custom time.' ),
) );
function themeslug_sanitize_time( $input ) {
$time = new DateTime( $input );
return $time->format('H:i');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment