Created
January 12, 2024 19:39
-
-
Save gugaalves/3cee2f7acf67ec3e0229cbcb1417fbec to your computer and use it in GitHub Desktop.
Events Calendar + Rank Math SEO: Noindex past events automatically
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
// 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