Last active
April 30, 2023 19:05
-
-
Save cliffordp/2e5c53412171363b66864087b6a75bad to your computer and use it in GitHub Desktop.
The Events Calendar - Redirect single event view page to its Event Website
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 | |
/** | |
* The Events Calendar - Redirect single event view page to its Event Website | |
* | |
* The regular single event view page will be loaded if the event does not have a valid Event Website URL. | |
* | |
* From https://gist.github.com/cliffordp/2e5c53412171363b66864087b6a75bad | |
* | |
* For https://theeventscalendar.com/support/forums/topic/recurring-event-custom-event-link-behind-events-calendar/ | |
*/ | |
add_action( 'template_redirect', 'cliff_redirect_tec_event_to_its_website_url' ); | |
function cliff_redirect_tec_event_to_its_website_url() { | |
if ( | |
! class_exists( 'Tribe__Events__Main' ) | |
|| ! is_singular( Tribe__Events__Main::POSTTYPE ) | |
) { | |
return false; | |
} | |
$redirect_to = esc_url_raw( tribe_get_event_website_url( get_the_ID() ) ); | |
if ( empty( $redirect_to ) ) { | |
return false; | |
} else { | |
// 301 is permanent. 302 is temporary. | |
// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection | |
// function's default is 302 | |
wp_redirect( $redirect_to, 301 ); | |
exit; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for sharing this, Clifford. Very helpful.