Skip to content

Instantly share code, notes, and snippets.

@elimn
Created March 17, 2016 07:18
Show Gist options
  • Save elimn/ae3e234aecf46753618b to your computer and use it in GitHub Desktop.
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
<?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