The Events Calendar Date Format Shortcode

It might be useful to show the data in the desired format, so I created a shortcode to accomplish that, append the next code to functions.php of your child theme

add_shortcode( 'event_date', 'us_event_date_formatting' );
function us_event_date_formatting() {
	$postID = get_the_ID();
	if ( ! $postID ) {
		return FALSE;
	}

	$value = get_post_meta( $postID, '_EventStartDateUTC', TRUE );
	if ( ! $value ) {
		return FALSE;
	}

	$date = new DateTime( $value );
	// Date Formats https://www.php.net/manual/en/function.date.php
	$format = 'M d Y';
	$date = date_format( $date, $format );

	return $date;
}

Once everything is set, use the [event_date] shortcode to show the formatted date on any page of your site.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.