Make WordPress Core


Ignore:
Timestamp:
10/23/2023 03:40:44 PM (11 months ago)
Author:
swissspidy
Message:

Sitemaps: add lastmod for individual posts and the homepage.

When the XML sitemaps feature was originally introduced, the lastmod field was omitted because guidance at the time indicated it was less important for search engines, plus for some entities it was computationally expensive to add. Now that the guidance has slightly changed, we are revisiting this and adding lastmod where easily possible.

  • Adds lastmod to all individual post objects (of any post type) in the sitemap
  • Adds lastmod to the homepage sitemap entry if the homepage is set to display the latest posts.

No lastmod is added for the individual sitemap pages in the sitemap index, nor for term archives or user archives. Those enhancements require additional changes, such as storing the modified date for a taxonomy term when something is added to that term. They can be revisited in separate follow-up tickets.

Props swissspidy, joemcgill.
Fixes #52099

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/sitemaps/sitemaps.php

    r51492 r56985  
    252252        $post_list = $providers['posts']->get_url_list( 1, 'page' );
    253253
     254        $post_list_sorted = wp_list_sort( $post_list, 'lastmod', 'DESC' );
     255
    254256        $expected = $this->_get_expected_url_list( 'page', self::$pages );
    255257
     
    258260            $expected,
    259261            array(
    260                 'loc' => home_url( '/' ),
     262                'loc'     => home_url( '/' ),
     263                'lastmod' => $post_list_sorted[0]['lastmod'],
    261264            )
    262265        );
     
    379382            static function ( $post ) {
    380383                return array(
    381                     'loc' => get_permalink( $post ),
     384                    'loc'     => get_permalink( $post ),
     385                    'lastmod' => get_post_modified_time( DATE_W3C, true, $post ),
    382386                );
    383387            },
Note: See TracChangeset for help on using the changeset viewer.