Sometimes The Events Calendar creates multiple links that are indexed by search engines. This may cause some SEO and performance issues on your website. The good news is that our plugin adds a noindex meta tag to your page header if t here’s no events listed on that page, to block this duplicate content.
Block Duplicate Content
If there are no events for a specific URL that you see multiple links created for, TEC adds the following noindex meta tag to your page’s header:
<meta name="robots" content="noindex">
You can also block Google and other search engines from crawling undesired/empty pages by disallowing some URL paths in the robots.txt file.
To achieve that, you can add a robots.txt file to your server’s root folder or manage it using SEO plugins.
The following parameters will help block some WordPress folders and URLs, and also Events Calendar parameters:
## For WordPress
User-agent: *
Disallow: /wp-admin/*
Disallow: /wp-login.php
Disallow: /wp-includes/*
Disallow: /wp-content/*
Disallow: /trackback
Disallow: /feed
Disallow: */comments
Disallow: ?replytocom*
Disallow: */comments-page-*
Disallow: */trackback
Disallow: */feed
Disallow: */comments
Allow: /wp-content/cache/*
Allow: /wp-content/uploads/*
Allow: /wp-content/themes/*
Allow: /wp-content/plugins/*
Allow: /wp-includes/js/*
Allow: /wp-includes/css/*
## For Events Calendar
Disallow: *post_type=tribe_events*
Disallow: *hide_subsequent_recurrences=*
Disallow: *tribe-bar-date=*
Disallow: *tribe-venue=*
Disallow: *eventDisplay=*
Disallow: *eventDate=*
Disallow: *paged=*
Disallow: *pagename=*
Disallow: *shortcode=*
Disallow: *ical=*
Disallow: *outlook-ical=*
Disallow: *related_series=*
Disallow: *tribe_geofence=*
Disallow: *tribe_organizer=*
Allow: /events/*
Allow: /event/*
With the Yoast SEO plugin, you can edit your robots.txt file under wp-admin > Yoast SEO > Tools > File editor. Read more in their documentation here.
Using the Rank Math SEO plugin, you can edit the robots.txt file under wp-admin > Rank Math > General Settings > Edit robots.txt. Documentation here.
Remove Indexing from Recurring Event Occurrences
If you want to prevent recurring event occurrences from being indexed by Google, you can use this snippet to automatically add a noindex tag for all occurrences.
add_action( 'wp_head', 'tec_add_nofollow_to_recurring_events' );
/**
* Add 'nofollow' to recurring events occurrences
*
* @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 it's a recurring event, add the noindex meta tag
if ( tribe_is_recurring_event($event_id) ) {
echo '<meta name="robots" id="tec_noindex" content="noindex, follow" />' . "\n";
}
}
If you’re looking to have only the first recurrence indexed by Google but not all the subsequent ones, you’ll need to tweak that code not to include the noindex tag for the first event occurrence.
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 '<meta name="robots" id="tec_noindex" content="noindex, follow" />' . "\n";
}
}
}
Add noindex to the Legacy Recurring Events Page
If you’ve been using The Events Calendar for a while, you may have legacy pages for old recurring events (/event/[event-name]/all). That page has been replaced by the Series archive page. The following snippet that adds noindex to this page, since it’s no longer relevant. You can add it to your functions.php file when using Yoast SEO:
if(class_exists('WPSEO_Options')){
add_filter("wpseo_robots", function($robots) {
global $wp_query;
if ( $wp_query->tribe_is_recurrence_list && 'all' === $wp_query->get( 'eventDisplay' )) {
return "noindex";
}
return $robots;
});
}
If you are using Rank Math, here is the example snippet using the proper filters for that plugin:
add_filter( 'rank_math/frontend/robots', function ( $robots ) {
global $wp_query;
if ( $wp_query->tribe_is_recurrence_list && 'all' === $wp_query->get( 'eventDisplay' )) {
unset( $robots['index'] );
$robots['noindex'] = 'noindex';
}
return $robots;
});