# Last Modified Dates in the XML Sitemap

> Adds the date each post was last updated to the built-in sitemap, which helps search engines find changed content faster.

- Type: PHP
- Runs: Run everywhere
- Category: [SEO](https://wpide.com/library/category/seo/)
- Tags: sitemap, lastmod, crawling
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/sitemap-last-modified-dates/

## Code

```php
add_filter( 'wp_sitemaps_posts_entry', function ( $entry, $post ) {
    $entry['lastmod'] = get_post_modified_time( 'c', true, $post );

    return $entry;
}, 10, 2 );
```

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Last Modified Dates in the XML 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/
