# Redirect Long-Past Events to the Calendar

> Sends visitors (and search engines) from single events that ended more than a set number of days ago to the main events page with a 301 redirect, keeping your calendar fresh.

- Type: PHP
- Runs: Frontend cl
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: events-calendar, redirect, past-events
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/tec-redirect-old-past-events/

## Code

```php
$wpide_days = 90; // Redirect events that ended more than this many days ago.

add_action( 'template_redirect', function () use ( $wpide_days ) {
    if ( ! is_singular( 'tribe_events' ) || current_user_can( 'edit_posts' ) || ! function_exists( 'tribe_get_events_link' ) ) {
        return;
    }

    $end = strtotime( (string) get_post_meta( get_queried_object_id(), '_EventEndDate', true ) );

    if ( $end && $end < current_time( 'timestamp' ) - $wpide_days * DAY_IN_SECONDS ) { // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested -- event dates are stored in site time.
        wp_safe_redirect( tribe_get_events_link(), 301 );
        exit;
    }
} );
```

## Notes

Change $wpide_days. Logged-in editors can still view old events.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Redirect Long-Past Events to the Calendar" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
