Skip to content

Instantly share code, notes, and snippets.

@neilgee
Created September 14, 2018 07: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 neilgee/d67ff7310441b680e1d0ad575994b330 to your computer and use it in GitHub Desktop.
Save neilgee/d67ff7310441b680e1d0ad575994b330 to your computer and use it in GitHub Desktop.
Modern Tribe Events Date Output
<?php // <~ don't add me in
add_shortcode( 'all_the_single_dates', 'all_the_single_dates' );
// Event Dates - display single date only for single dates & multi dates for multiple day events
function all_the_single_dates() {
// Get the start date and end date
// https://pastebin.com/ij0g9Tcf
// https://theeventscalendar.com/support/forums/topic/remove-end-date-if-same-as-start-date/#post-46651
ob_start();
$start_date = tribe_get_start_date(null, false,'d F');
$end_date = tribe_get_end_date(null, false, 'd F');
$start_date_day = tribe_get_start_date(null, false,'d');
$end_date_day = tribe_get_end_date(null, false, 'd');
$start_date_month = tribe_get_start_date(null, false,'F');
$end_date_month = tribe_get_end_date(null, false, 'F');
$start_date_year = tribe_get_start_date(null, false,'d F Y');
$end_date_year = tribe_get_end_date(null, false, 'd F Y');
// Only show the end date if it is different to the start date
if ($start_date !== $end_date) {
if ($start_date_month !== $end_date_month){
$start_date .= " &ndash; $end_date_year";
}
else {
$start_date = $start_date_day;
$start_date .= " &ndash; $end_date_year";
}
}
else {
$start_date = "$start_date_year";
}
?>
<p class="event-date"><?php esc_html_e($start_date) ?></p>
<?php
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment