This function lets you detect if the Time Format in WordPress settings is set to a 24-hour format. It returns true if the Time Format is in a 24-hour format, otherwise it returns false. (The Time Format is also known as the ‘time_format’ option, and you can get it like this: get_option( 'time_format' )
.)
/** * Detect if time_format is in 24hr format * @return bool true if hour is in 24hr format, otherwise false. */ function isa_is_time_format_24_hour() { $out = false; // some possible separators in the time format string, besides a 'space' $sep = array( ':', ',', '-', '/', '.' ); $time_format = get_option( 'time_format' ); $time_format_elements = array_filter( explode( ' ', str_replace( $sep, ' ', $time_format ) ) ); $time_format_elements = array_values( $time_format_elements ); $hour_24hr_formats = array( 'G', 'H' ); // check if any time format elements are a 24hr format foreach( $hour_24hr_formats as $element ) { if ( in_array( $element, $time_format_elements ) ) { $out = true; } } return $out; }
Questions and Comments are Welcome