Set robots noindex for past events

This snippet sets meta robots to noindex for past events created by The Event Calendar plugin. It works for Slim SEO only:

add_filter( 'slim_seo_robots_index', function ($value, $object_id) {
    if ( ! is_singular( 'tribe_events' ) ) {
        return $value;
    }

    $event_timestamp = strtotime( tribe_get_start_date( $object_id, false, 'Y-m-d' ) );

    return $event_timestamp < strtotime( '-7 days' ) ? false : $value;
}, 10, 2 );

🔥 HOT: Interested in boosting your WordPress SEO? My Slim SEO plugin is a super lighweight and automated plugin that handles most the hard work for you: meta tags, sitemap, redirection, schema & link building.

👉 Have a look and you will love it: wpslimseo.com

Copyright © 2024 Deluxe Blog Tips. All rights reserved.

My products: Meta Box | Slim SEO