Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active April 30, 2023 19:05
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cliffordp/2e5c53412171363b66864087b6a75bad to your computer and use it in GitHub Desktop.
The Events Calendar - Redirect single event view page to its Event Website
<?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;
}
@janmaarten-a11y
Copy link

Thank you for sharing this, Clifford. Very helpful.

@cliffordp
Copy link
Author

@worldsayer 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment