At WPBeginner, we prioritize transparency by displaying the last modified date on all our articles instead of just the original publish date. Completely removing dates from WordPress posts isn't ideal for user trust. If you're highlighting modifications like we do, showcasing recently updated posts can keep visitors informed. In this step-by-step guide, we'll show you how to display a list of the latest updated posts in WordPress.
WordPress automatically records the update timestamp in the posts table's post_modified field. Using a custom query, you can easily fetch and list your most recently modified articles.
Add this proven code to a site-specific plugin or your active theme's functions.php file:
function wpb_lastupdated_posts() {
// Query args
$lastupdated_args = array(
'orderby' => 'modified',
'ignore_sticky_posts' => 1,
'posts_per_page' => 5
);
// The query
$lastupdated_loop = new WP_Query($lastupdated_args);
$output = '<ul>';
$counter = 1;
while ($lastupdated_loop->have_posts() && $counter <= 5) : $lastupdated_loop->the_post();
$output .= '<li><a href="' . get_permalink(get_the_ID()) . '">' . get_the_title() . ' (' . get_the_modified_date() . ')</a></li>';
$counter++;
endwhile;
$output .= '</ul>';
wp_reset_postdata();
return $output;
}
add_shortcode('lastupdated-posts', 'wpb_lastupdated_posts');To embed in theme template files (like sidebar.php), simply add:
<?php echo wpb_lastupdated_posts(); ?>
For posts, pages, or widgets, use the shortcode: [lastupdated-posts].
WordPress offers flexible sorting options beyond publish date—by modified date, random, or custom fields. This method empowers you to spotlight fresh updates effortlessly.
How do you handle dates on your site—original publish or last modified? Share in the comments below.