Make WordPress Core

Opened 9 months ago

Last modified 2 months ago

#52099 reopened enhancement

Sitemaps "Last Modified" (lastmod) tag

Reported by: junaidbhura Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 5.5
Component: Sitemaps Keywords: needs-patch
Focuses: performance Cc:


Sitemaps currently only support the "Location" tag (loc). This ticket adds support for the "Last Modified" tag.

This is how it works:

1. Posts

This is probably the easiest - it just takes the post_modified_gmt value of the post and creates a lastmod tag.

2. Taxonomies

It gets the latest modified post in the taxonomy and creates a lastmod tag based on its last modified value.

3. Users

It gets the latest modified post by a user and creates a lastmod tag based on its last modified value.

4. Indices

Sitemap indices / indexes work in this way:

  1. If its a post index - get the last modified date of the last updated post in the post type
  2. If its a taxonomy index - get the last modified date of the last updated post which is associated with any term in the taxonomy
  3. If its a user index - get the last modified date of the post type "post" - since all posts are associated with users

Attachments (2)

52099.diff (12.1 KB) - added by junaidbhura 9 months ago.
52099.2.diff (12.1 KB) - added by junaidbhura 9 months ago.

Download all attachments as: .zip

Change History (11)

9 months ago

This ticket was mentioned in PR #822 on WordPress/wordpress-develop by junaidbhura.

9 months ago

  • Keywords has-unit-tests added

#2 @prbot
9 months ago

github-actions[bot] commented on PR #822:

Hi @junaidbhura! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description.

Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making.

More information about how GitHub pull requests can be used to contribute to WordPress can be found in this blog post.

Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook.

If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook.

The Developer Hub also documents the various coding standards that are followed:

Thank you,
The WordPress Project

#3 @junaidbhura
9 months ago

Hey @peterwilsoncc do you think you could take a look at this and let me know what you think?


9 months ago

#4 @MadtownLems
9 months ago

I believe that this was intentionally left in plugin territory, at least partially because "last modified" for a post can be much more complicated than this when you consider dynamic content.

If a page's primary function is to embed a YouTube playlist, twitch channel, etc - the page gets new content whenever those things update.

The same is true for pages that pull content from other sources, such as a third party calendaring system, RSS feeds, or even just using the Latest Posts block.

Furthermore, most search engines don't actually consume these other tags.

Here's an excerpt from the blog post announcing the new functionality (https://make.wordpress.org/core/2020/07/22/new-xml-sitemaps-functionality-in-wordpress-5-5/):

"The sitemaps protocol specifies a certain set of supported attributes for sitemap entries. Of those, only the URL (loc) tag is required. All others (e.g. changefreq and priority) are optional tags in the sitemaps protocol and not typically consumed by search engines, which is why WordPress only lists the URL itself. Developers can still add those tags if they really want to."

#5 @pbiron
9 months ago

  • Version changed from 5.6 to 5.5

Version 0.2.0 of the core sitemaps feature plugin was the last one to include support for lastmod.

All support for lastmod was removed in Remove all traces of lastmod, PR 145.

You can check out that PR, which contains links to the issues and slack conversations around that.

In addition to what @MadtownLems mentions, in large sites lastmod can be expensive to compute.

#6 @junaidbhura
9 months ago

  • Resolution set to wontfix
  • Status changed from new to closed

Didn't realise that it was purposely left out - thanks for pointing this out. I'll close this ticket out!

#7 @desrosj
6 months ago

  • Milestone Awaiting Review deleted

#8 @ocean90
2 months ago

#53740 was marked as a duplicate.

#9 @swissspidy
2 months ago

  • Focuses performance added
  • Keywords needs-patch added; has-patch has-unit-tests removed
  • Milestone set to Future Release
  • Resolution wontfix deleted
  • Status changed from closed to reopened

Reopening after talking to @garyillyes regarding #53740.

While Google does not currently use <lastmod>, other search engines consume it to schedule crawls more effectively, saving resources and decreasing load on sites.

It's true that we removed lastmod originally to keep things simple and performant, perhaps there is some middle ground where we can add it without much overhead.

For example, adding lastmod for posts is probably trivial, but for other entries and especially the homepage it might not be, and we could consider those cases plugin territory.

Expensive queries could be cached via wp_cache_add or similar to ensure there's no impact on larger sites.

Note: See TracTickets for help on using tickets.