Skip to content

Instantly share code, notes, and snippets.

@gugaalves
Created January 12, 2024 19:39
Show Gist options
  • Save gugaalves/3cee2f7acf67ec3e0229cbcb1417fbec to your computer and use it in GitHub Desktop.
Save gugaalves/3cee2f7acf67ec3e0229cbcb1417fbec to your computer and use it in GitHub Desktop.
Events Calendar + Rank Math SEO: Noindex past events automatically
// That snippet was tested using the following plugin versions:
// The Events Calendar v6.2.9
// Rank Math SEO v1.0.210
// Check if Events Calendar and Rank Math plugins are enabled
if (class_exists('Tribe__Events__Main') && class_exists('RankMath')) {
add_filter( 'rank_math/frontend/robots', function( $robots ) {
global $post;
if (!is_admin() && is_singular() && @$post->post_type == 'tribe_events') {
if (strtotime(tribe_get_end_date($post->ID, true, 'r')) < time()) {
unset( $robots['index'] );
$robots['noindex'] = 'noindex';
}
return $robots;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment