add_action( 'wp_head', 'tec_add_nofollow_to_recurring_events' );
/**
* Add 'nofollow' to recurring events, except for the first instance.
*
* @return void
*/
function tec_add_nofollow_to_recurring_events() {
// Bail if ECP is not active.
if ( ! class_exists( 'Tribe__Events__Pro__Main' ) ) {
return;
}
// Get the post ID.
$event_id = get_the_ID();
// Bail, if it's not an event.
if ( get_post_type( $event_id ) != "tribe_events" ) {
return;
}
// Bail, if it's not a single event
if ( ! is_single() ){
return;
}
if ( tribe_is_recurring_event($event_id) ){
// Get the post object.
$post = get_post( $event_id );
// Check if the event is the first in the recurrence.
$is_first = \TEC\Events\Custom_Tables\V1\Models\Occurrence::is_first( $post->_tec_occurrence );
// If it's not the first recurrence, add the noindex meta tag
if ( !$is_first ) {
echo '' . "\n";
}
}
}Skip to content