Today I’m going to share with you a simple snippet for Wordpress that displays the date of last modified blog post. As always, you should add this snippet to the functions.php file of your child theme. Good luck!
function last_modified_date($content) {
// Check if the current view is a single post
if (is_single()) {
// Get the last modified date of the post
$modified_date = get_the_modified_time('F jS Y');
if ($modified_date) {
// Display the last updated date in a div container
?>
<div class="last-updated">
<?php echo sprintf(
esc_html__('Last updated on %1$s'),
$modified_date
); ?>
</div>
<?php
}
}
// Return the content, possibly modified with the last updated date
return $content;
}
// Add the function to the 'the_content' filter hook
add_filter('the_content', 'last_modified_date');
Leave a Reply