Last active
March 13, 2025 17:33
-
-
Save jo-snips/2415009 to your computer and use it in GitHub Desktop.
The Events Calendar: Basic Conditional Wrappers
This file contains hidden or 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 | |
/*-----------------------------------------------------------------------------------*/ | |
/* Conditional Logic to Detect Various Event Related Views/Pages | |
/*-----------------------------------------------------------------------------------*/ | |
if( tribe_is_month() && !is_tax() ) { // Month View Page | |
echo 'were on the month view page'; | |
} elseif( tribe_is_month() && is_tax() ) { // Month View Category Page | |
echo 'were on the month view category page'; | |
} elseif( tribe_is_past() || tribe_is_upcoming() && !is_tax() ) { // List View Page | |
echo 'were on the list view page'; | |
} elseif( tribe_is_past() || tribe_is_upcoming() && is_tax() ) { // List View Category Page | |
echo 'were on an list view category page'; | |
} elseif( tribe_is_week() && !is_tax() ) { // Week View Page | |
echo 'were the week view page'; | |
} elseif( tribe_is_week() && is_tax() ) { // Week View Category Page | |
echo 'were the week view category page'; | |
} elseif( tribe_is_day() && !is_tax() ) { // Day View Page | |
echo 'were on the day view page'; | |
} elseif( tribe_is_day() && is_tax() ) { // Day View Category Page | |
echo 'were on a day view category page'; | |
} elseif( tribe_is_map() && !is_tax() ) { // Map View Page | |
echo 'were on the map view page'; | |
} elseif( tribe_is_map() && is_tax() ) { // Map View Category Page | |
echo 'were on the map view category page'; | |
} elseif( tribe_is_photo() && !is_tax() ) { // Photo View Page | |
echo 'were on the photo view page'; | |
} elseif( tribe_is_photo() && is_tax() ) { // Photo View Category Page | |
echo 'were on the photo view category page'; | |
} elseif( tribe_is_event() && is_single() ) { // Single Events | |
echo 'were on a single event page'; | |
} elseif( tribe_is_venue() ) { // Single Venues | |
echo 'were on a single venue page'; | |
} elseif( get_post_type() == 'tribe_organizer' && is_single() ) { // Single Organizers | |
echo 'were on a single organizer page'; | |
} else { | |
} |
To see if I'm on any event page, I just use tribe_is_event_query(). I don't know if even widgets return true on this, but since I don't use event widgets, It seems to work.
I had a problem with all these functions at some point when updating the event plugins. When the versions of TEC and TEC pro don't match, the plugin isn't loaded and the tribe_is_ functions are not reliably available, what results in fatal errors. To prevent that I not only test if the plugin is active, by checking if Tribe__Events__Main or Tribe__Events__Pro__Main exists, but also if the functions are available, since I found and can't count on that even after checking the class for availability.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an easier way to target the "List View":
tribe_is_list_view()