Skip to content

Instantly share code, notes, and snippets.

@lorenzocaum
Created July 6, 2015 20:40
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 lorenzocaum/41f70b94f7c6b212b145 to your computer and use it in GitHub Desktop.
Save lorenzocaum/41f70b94f7c6b212b145 to your computer and use it in GitHub Desktop.
How to hide the date in the date time for Event Espresso 4 and show only the time

The following sample code can be added to your child theme's functions.php file or in a site specific plugin.

It will show the date time with only the time. This will apply to the event listings page and the single event pages.

<?php
//* Do NOT include the opening php tag

//* Override default list of event dates function to show only the time
if ( ! function_exists( 'espresso_list_of_event_dates' )) {
	/**
	 * espresso_list_of_event_dates
	 * returns a unordered list of dates for an event
	 *
	 * @param int    $EVT_ID
	 * @param string $date_format
	 * @param string $time_format
	 * @param bool   $echo
	 * @param null   $show_expired
	 * @param bool   $format
	 * @param bool   $add_breaks
	 * @param null   $limit
	 * @return string
	 */
	function espresso_list_of_event_dates( $EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL ) {
		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
		$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
		$date_format = apply_filters( 'FHEE__espresso_list_of_event_dates__date_format', $date_format );
		$time_format = apply_filters( 'FHEE__espresso_list_of_event_dates__time_format', $time_format );
		EE_Registry::instance()->load_helper( 'Event_View' );
		$datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, $show_expired, FALSE, $limit );
		if ( ! $format ) {
			return apply_filters( 'FHEE__espresso_list_of_event_dates__datetimes', $datetimes );
		}
		//d( $datetimes );
		if ( is_array( $datetimes ) && ! empty( $datetimes )) {
			global $post;
			$html = $format ? '<ul id="ee-event-datetimes-ul-' . $post->ID . '" class="ee-event-datetimes-ul">' : '';
			foreach ( $datetimes as $datetime ) {
				if ( $datetime instanceof EE_Datetime ) {
					$html .= '<li id="ee-event-datetimes-li-' . $datetime->ID() . '" class="ee-event-datetimes-li">';
					$datetime_name = $datetime->name();
					$html .= ! empty( $datetime_name ) ? '<strong>' . $datetime_name . '</strong>' : '';
					$html .= ! empty( $datetime_name )  && $add_breaks ? '<br />' : '';
					// $html .= '<span class="dashicons dashicons-calendar"></span>' . $datetime->date_range( $date_format ) . '<br/>';
					$html .= '<span class="dashicons dashicons-clock"></span>' . $datetime->time_range( $time_format );
					$datetime_description = $datetime->description();
					$html .= ! empty( $datetime_description )  && $add_breaks ? '<br />' : '';
					$html .= ! empty( $datetime_description ) ? ' - ' . $datetime_description : '';
					$html = apply_filters( 'FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime );
					$html .= '</li>';
				}
			}
			$html .= $format ? '</ul>' : '';
		} else {
			$html = $format ?  '<p><span class="dashicons dashicons-marker pink-text"></span>' . __( 'There are no upcoming dates for this event.', 'event_espresso' ) . '</p><br/>' : '';
		}
		if ( $echo ) {
			echo $html;
			return '';
		}
		return $html;
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment