Created
March 17, 2016 07:18
-
-
Save elimn/ae3e234aecf46753618b to your computer and use it in GitHub Desktop.
MT | TEC | Swap the canonical URL for the /all/ page on recurring events
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 | |
/* | |
* Swaps the canonical URL for the /all/ page on recurring events | |
*/ | |
function tribe_recurring_canonical_adjuster() { | |
if ( ! tribe_is_recurring_event() ) return; | |
remove_action( 'wp_head', 'rel_canonical' ); | |
add_action( 'wp_head', 'tribe_rel_canonical' ); | |
} | |
add_action( 'wp', 'tribe_recurring_canonical_adjuster' ); | |
/* | |
* Echoes the <meta> canonical= /all/ tag | |
*/ | |
function tribe_rel_canonical() { | |
$postId = get_queried_object_id(); | |
// set the EventStartDate so Tribe__Events__Main can filter the permalink appropriately | |
$post = get_post( $postId ); | |
$post->EventStartDate = get_query_var( 'eventDate' ); | |
$link = tribe_all_occurences_link( $postId, false ); | |
echo "<link rel='canonical' href='" . esc_url( $link ) . "' />\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment