WordPress already stores two key timestamps for every post:
-
post_date→ when the post was first published -
post_modified→ when it was last edited
So instead of creating a new custom field, we can simply compare these values and display the “Last Updated” date only when the post has been modified after publishing.

PHP Code for functions.php
Add the following snippet to your theme’s functions.php file:
/**
* Display "Last Updated" date automatically in posts
*/
function show_last_updated_date() {
if (is_singular('post')) {
global $post;
$modified_time = get_the_modified_time('U');
$published_time = get_the_time('U');
// Show only if the post has been updated
if ($modified_time > $published_time) {
$modified_date = get_the_modified_time(get_option('date_format'));
echo '<p class="last-updated">🕓 Last updated: ' . esc_html($modified_date) . '</p>';
}
}
}
add_action('the_content', function($content) {
if (is_singular('post')) {
ob_start();
show_last_updated_date();
$last_updated = ob_get_clean();
return $last_updated . $content;
}
return $content;
});
💡 You can replace “Last updated:” with any custom text, such as your preferred language or label style.
Optional Styling
To make it look clean and minimal, add this CSS in Appearance → Customize → Additional CSS:
.last-updated {
font-size: 14px;
color: #777;
margin-bottom: 12px;
font-style: italic;
}
You can target the
.last-updatedclass in your CSS to fully customize its style and match your site’s design system.
- Automatically adds a “Last Updated” line above the post content
- Works only for posts that were edited after publication
- Uses your site’s default date format (
Settings → General → Date Format) - No plugin required — lightweight and fully native