How to Display WordPress Posts by Last Modified Date in Twenty Twenty-Five Theme

annie spratt 3mvHZQzSBss unsplash scaled

To always display the most recently modified articles at the top of your Twenty Twenty-Five site, add the following code to your theme’s functions.php file. This sorts posts by the last modified date instead of the original publish date on the home and archive pages.


Display Posts by Last Modified Date (Method 1)

phpfunction sort_posts_by_modified_date($query) {
  if (!is_admin() && $query->is_main_query() && (is_home() || is_archive())) {
    $query->set('orderby', 'modified');
    $query->set('order', 'DESC');
  }
}
add_action('pre_get_posts', 'sort_posts_by_modified_date');

How it works:

  • This function hooks into WordPress’ main post query before it’s executed.
  • It checks if you’re viewing the homepage or an archive page (not in the admin area).
  • It changes the query to sort by the modified date, showing the most recently edited posts first.

To apply:

  1. Go to Appearance → Theme File Editor.
  2. Open your active theme’s functions.php.
  3. Paste the code above at the bottom and save.

Result:
Your blog and archives will now display posts in order of last modification date, keeping updated content at the top and letting readers find your freshest articles first.

Genx

in

About The Author

Genx

Born in 1982 in Japan, he is a Japanese beatmaker and music producer who produces experimental hiphop beats. He is the owner of Genx Records. Because he grew up internationally, he understands English. His hobbies are muscle training, artwork creation, website customization, and web3. He also loves Korea.

Website: genxrecords.xyz

Share This Post:


Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

5 × one =

Webmention: Have you posted a response to this article? Let me know the URL: