Skip to content

Instantly share code, notes, and snippets.

@jasperfrontend
Last active March 25, 2024 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasperfrontend/a83a712e1087a63b34d07fccfe11eddc to your computer and use it in GitHub Desktop.
Save jasperfrontend/a83a712e1087a63b34d07fccfe11eddc to your computer and use it in GitHub Desktop.
<?php
// My time shortcode [mytime timezone="Europe/Amsterdam" format="h:i A"]
// You can also edit the defaults on lines 7 & 8, then you can just use [mytime] to show your current time
add_shortcode( 'mytime', 'imw_my_time' );
function imw_my_time( $atts ) {
$atts = shortcode_atts( array(
'timezone' => 'Europe/Amsterdam',
'format' => 'h:i A'
), $atts, 'mytime' );
$timezone = new DateTimeZone( $atts['timezone'] );
$return = wp_date($atts['format'], null, $timezone );
return $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment