# Leave Old Posts Out of the All in One SEO Sitemap

> Removes post entries that have not been modified for several years from All in One SEO's post sitemap.

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

## Code

```php
// Entries not modified for this many years are dropped.
$wpide_aioseo_max_age = 3;

add_filter( 'aioseo_sitemap_posts', function ( $entries, $post_type ) use ( $wpide_aioseo_max_age ) {
    if ( 'post' !== $post_type || ! is_array( $entries ) ) {
        return $entries;
    }

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

    return array_values( array_filter( $entries, function ( $entry ) use ( $cutoff ) {
        $time = isset( $entry['lastmod'] ) ? strtotime( (string) $entry['lastmod'] ) : false;

        return ! $time || $time >= $cutoff;
    } ) );
}, 10, 2 );
```

## Notes

Only the "post" type is filtered; pages and other types are kept.

## How to use it

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