# Leave Old Posts Out of the Yoast Sitemap

> Removes posts that have not been updated for a number of years from the Yoast SEO post sitemap, so crawlers spend time on fresher content.

- Type: PHP
- Runs: Frontend only
- Category: [Plugin Integrations](https://wpide.com/library/category/integrations/)
- Tags: yoast, sitemap, crawl-budget
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/yoast-sitemap-skip-old-posts/

## Code

```php
// Posts not modified for this many years are left out.
$wpide_sitemap_max_age_years = 3;

add_filter( 'wpseo_sitemap_entry', function ( $url, $type, $object ) use ( $wpide_sitemap_max_age_years ) {
    if ( 'post' !== $type || ! $object instanceof WP_Post || 'post' !== $object->post_type ) {
        return $url;
    }

    $cutoff = strtotime( '-' . absint( $wpide_sitemap_max_age_years ) . ' years' );

    return strtotime( $object->post_modified_gmt . ' UTC' ) < $cutoff ? false : $url;
}, 10, 3 );
```

## Notes

The posts stay published and indexable; only the sitemap entry goes.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Leave Old Posts Out of the Yoast Sitemap" 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/
