Problem:
Sitemap order isn’t based on last modified date; plugins don’t reorder based on updates.
when we update post in wordpress the last modified date changes but not in top or begiging postition oof the sitemap with rank math seo, yoast or any wordpress xml sitemap.
what we want:
Last updated page should be first position so google can easily crawl top pages. as well site admins can see last updated pages in chronoloical order
Short answer Re‑ordering your sitemap won’t make Google crawl those URLs sooner. Google doesn’t use the visual order of sitemap URLs as a priority signal; it uses lastmod, internal linking, importance, and crawl budget. That said, sorting by “last updated” is still handy for humans—and it won’t hurt.
Below are safe, copy‑paste solutions to put most‑recently‑modified URLs first in sitemaps (where supported) and to give admins a sortable “Last Modified” view in wp‑admin.
- WordPress core sitemap (wp-sitemaps) – sort by last modified
If you use the native WordPress sitemap (WP 5.5+), add this to a small must-use plugin or Code Snippets:
// Order core WordPress sitemaps by most-recently modified first.
add_filter( 'wp_sitemaps_posts_query_args', function( $args, $post_type ) {
$args['orderby'] = 'modified'; // sorts by post_modified
$args['order'] = 'DESC';
return $args;
}, 10, 2 );
- Yoast SEO – sort sitemap by last modified
Yoast exposes a clean filter for the ORDER BY clause:
// Yoast: show latest updated content first in post-type sitemaps.
add_filter( 'wpseo_posts_orderby', function( $orderby, $post_type ) {
// Use GMT column for consistency, fall back to ID for tie-breaker.
return 'post_modified_gmt DESC, ID DESC';
}, 10, 2 );
Notes:
- Works per post-type sitemap (post-sitemap.xml, page-sitemap.xml, etc.).
- After adding, purge caches and refresh one sitemap page to rebuild.
- Rank Math – options
Rank Math doesn’t currently provide a widely-documented public filter just to change the URL order within its sitemaps. You have a few practical paths:
- Easiest: Use WordPress core sitemaps for posts/pages (with the filter in section 1) and keep Rank Math’s sitemap module off. Add the core sitemap URL to robots.txt and Search Console. You can run only one sitemap or list both; Google will handle it.
- Custom sitemap: Generate a simple custom sitemap (sorted by last modified) and list its URL in robots.txt alongside Rank Math’s. This gives you the “recent first” view for admins without touching Rank Math.
If Rank Math introduces an official “query args/orderby” filter in your version, you’d adapt it to set orderby => modified, order => DESC in their sitemap query. Until then, the core sitemap route is the cleanest.
- Make wp‑admin lists sortable by “Last Modified” (for editors/admins)
This adds a “Last Modified” column to Posts and Pages, sortable descending so your team always sees the freshest content first.
// Add "Last Modified" column to Posts and Pages, make it sortable.
add_filter( 'manage_posts_columns', function( $cols ) {
$cols['last_modified'] = 'Last Modified';
return $cols;
} );
add_filter( 'manage_pages_columns', function( $cols ) {
$cols['last_modified'] = 'Last Modified';
return $cols;
} );
add_action( 'manage_posts_custom_column', function( $column, $post_id ) {
if ( 'last_modified' === $column ) {
echo esc_html( get_date_from_gmt( get_post_field( 'post_modified_gmt', $post_id ), 'Y-m-d H:i' ) );
}
}, 10, 2 );
add_action( 'manage_pages_custom_column', function( $column, $post_id ) {
if ( 'last_modified' === $column ) {
echo esc_html( get_date_from_gmt( get_post_field( 'post_modified_gmt', $post_id ), 'Y-m-d H:i' ) );
}
}, 10, 2 );
add_filter( 'manage_edit-post_sortable_columns', function( $cols ) {
$cols['last_modified'] = 'modified';
return $cols;
} );
add_filter( 'manage_edit-page_sortable_columns', function( $cols ) {
$cols['last_modified'] = 'modified';
return $cols;
} );
add_action( 'pre_get_posts', function( WP_Query $q ) {
if ( is_admin() && $q->is_main_query() && 'modified' === $q->get( 'orderby' ) ) {
$q->set( 'orderby', 'modified' );
$q->set( 'order', $q->get( 'order' ) ?: 'DESC' );
}
} );
- Quick checklist so Google actually sees freshness
- Ensure lastmod is correct: your SEO plugin should output lastmod from post_modified_gmt. If you update important custom fields without changing the post itself, consider programmatically “touching” the post to update post_modified.
- Don’t rely on sitemap order for crawling: keep internal links fresh (recent updates linked from strong pages), maintain a healthy crawl rate (fast site, no heavy 404s), and submit your sitemap(s) in Search Console.
- Clear cache/CDN after big updates so lastmod and pages are immediately visible.