Last active
August 23, 2018 05:23
-
-
Save cliffordp/acfde15af9cea91af4fbec168182fd1d to your computer and use it in GitHub Desktop.
The Events Calendar / PRO: Redirect tribe_events archive pages to custom page (MUST ENTER IT YOURSELF)
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 / PRO: | |
* Redirect tribe_events archive pages to custom page (MUST ENTER IT YOURSELF, BELOW) | |
* Does not carry-forward query string parameters | |
* | |
* From https://gist.github.com/cliffordp/acfde15af9cea91af4fbec168182fd1d | |
* | |
* @link https://theeventscalendar.com/knowledgebase/embedding-calendar-views-tribe_events-shortcode/ | |
*/ | |
add_action( 'template_redirect', 'tribe_events_redirect_custom_page' ); | |
function tribe_events_redirect_custom_page(){ | |
// | |
// BEGIN SETUP | |
// | |
// a relative URI like '/custom-events/' (probably worse for SEO) or a full URL beginning with http://... (probably better for SEO) | |
$redirect_to = ''; // e.g. 'http://wpshindig.com/my-custom-page-link/' | |
// 301 is permanent. 302 is temporary. | |
// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection | |
$redirection_code = 301; | |
// | |
// END SETUP, BEGIN LOGIC | |
// | |
if ( ! class_exists( 'Tribe__Events__Main' ) ) { | |
return false; | |
} | |
$tecmain = Tribe__Events__Main::instance(); | |
$redirect_to = esc_url_raw( $redirect_to ); | |
if ( empty( $redirect_to ) ) { | |
return false; | |
} | |
if ( is_main_query() && is_post_type_archive( $tecmain::POSTTYPE ) ) { | |
wp_redirect( $redirect_to, $redirection_code ); | |
exit; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment