Modern Tribe Events Date Output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 .= " – $end_date_year"; | |
} | |
else { | |
$start_date = $start_date_day; | |
$start_date .= " – $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