Last active
December 21, 2023 12:27
-
-
Save jo-snips/2415009 to your computer and use it in GitHub Desktop.
The Events Calendar: Basic Conditional Wrappers
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 | |
/*-----------------------------------------------------------------------------------*/ | |
/* 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 { | |
} |
There really should be an all encompassing is_tribe() or tribe_is() conditional tag.
For instance I'd like to have a plugin that says if this is "any" calendar item then do something.
As an example, I use a web governance SaaS that loves to charge by number of pages on a site and would like to exclude all calendar pages along with some other generated pages that don't need to be inspected.
add_action( 'wp_footer', 'my_footer_scripts' );
function my_footer_scripts(){
// Load script for home, pages, single posts except calendar pages and attachment posts.
if ( is_page() || is_home() || is_single() && ( ! ( is_attachment() || tribe_is() ) ) ) {
echo 'script loaded';
} else {
echo 'script not loaded';
// Don't load script
}
}
As a response to myself this will work. However, fewer checks would be ideal.
add_action( 'wp_footer', 'my_footer_scripts' );
function my_footer_scripts(){
// Load script for home, pages, single posts. Exclude all types of calendar pages and attachment posts.
if ( is_page() || is_home() || is_single() && ( ! ( is_attachment() || tribe_is_month() || tribe_is_past() || tribe_is_week() || tribe_is_day() || tribe_is_map || tribe_is_photo() || tribe_is_event() || tribe_is_venue() || get_post_type() == 'tribe_organizer' && is_single() ) ) ) {
echo 'script loaded';
} else {
echo 'script not loaded';
// Don't load script
}
}
Haven't tested it, but wouldn't something like this work?
function prefix_tribe_is() {
if ( class_exists( 'Tribe__Events__Main' ) ) {
return null !== Tribe__Events__Main::instance()->displaying ? true : false;
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the conditionals! I would have hoped conditionals for targeting all tribe pages at once or all calendar views at once and more would be part of the plugin, but this helps and solves the missing conditionals of the plugin.
Strange the is_tribe_organizer() is missing, since all other detail pages seem to have their own conditional.
In a lot of code snippets I also saw a wrapper if-statement testing on class_exists() for either tec or tec pro. Will the above code generate errors or warnings if the plugins are not installed?