Skip to content

Instantly share code, notes, and snippets.

@jbrinley
Created October 17, 2013 14:21
Show Gist options
  • Save jbrinley/7025774 to your computer and use it in GitHub Desktop.
Save jbrinley/7025774 to your computer and use it in GitHub Desktop.
Temporary fix for rel="canonical" links on recurring events when object caching is enabled
add_filter( 'wp', 'tribe_temporary_filter_canonical_link_on_recurring_events', 10, 1 );
function tribe_temporary_filter_canonical_link_on_recurring_events() {
if ( is_singular(TribeEvents::POSTTYPE) && get_query_var('eventDate') && has_action('wp_head', 'rel_canonical') ) {
remove_action( 'wp_head', 'rel_canonical' );
add_action( 'wp_head', 'tribe_temporary_output_recurring_event_canonical_link' );
}
}
function tribe_temporary_output_recurring_event_canonical_link() {
// set the EventStartDate so TribeEvents can filter the permalink appropriately
$post = get_post(get_queried_object_id());
$post->EventStartDate = get_query_var('eventDate');
// use get_post_permalink instead of get_permalink so that the post isn't converted
// back to an ID, then to a post again (without the EventStartDate)
$link = get_post_permalink( $post );
echo "<link rel='canonical' href='$link' />\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment