It’s a great idea to include the Published Date and Last Updated date on content you update regularly. This will let your readers know the content isn’t out-dated.
WordPress stores a published date and modified date for every post on your site.
You can use Limit Modified Date to make minor changes to an article (like fixing a typo) without changing the modified date.
There are a few ways you can display the modified date on your articles.
A Shortcode Option
If you’re using a Genesis theme, you can use shortcodes in the Post Info and Post Meta areas to display dynamic content (more information).
Genesis includes shortcodes for both the published date ([post_date]
) and the modified date ([post_modified_date]
). Here’s a full list of the available Genesis shortcodes.
But if you use the shortcode for modified date, it will always appear, even if it’s the same as the published date.
I personally prefer to only show the modified date if it’s more than a week later than the published date.
Add the code below to your theme’s functions.php file, or a core functionality plugin. You can then use [be_published_modified_date]
to display the published date, and include the modified date if it’s more than a week later.
/**
* Published & Modified Date
*
* @link https://www.billerickson.net/display-last-updated-date-on-articles/
*
*/
function be_published_modified_date() {
$date = get_the_date( 'U' );
$updated = get_the_modified_date( 'U' );
$output = '<span class="entry-date"><span class="label">Published on</span> ' . get_the_date( 'F j, Y' ) . '</span>';
if( $updated > ( $date + WEEK_IN_SECONDS ) )
$output .= ' <span class="entry-date-modified"><span class="label">Updated on</span> ' . get_the_modified_date( 'F j, Y' ) . '</span>';
return $output;
}
add_shortcode( 'be_published_modified_date', 'be_published_modified_date' );
A Code Option
If you prefer including the code directly in your theme, include the same code listed above.
Then add the following to your theme file (ex: single.php) where you’d like the published and modified date to appear.
echo be_published_modified_date();
Mike Hemberger says
Hey Bill,
Just showing a different option I’ve used with Genesis. It still uses the [post_modified_date] shortcode, but returns an empty string if it’s less than a week old. Check it out:
Doug says
Thanks for the writeup. A final dot to connect before I try deploying. After adding the ‘Published & Modified Date’ code to functions.php, I would then modify Post Info and include the [be_published_modified_date], such as below?
function be_post_info_filter($post_info) {
$post_info = ‘[be_published_modified_date] by [post_author_posts_link] [post_comments] [post_edit]‘;
return $post_info;
}
add_filter(‘genesis_post_info’, ‘be_post_info_filter’);
Bill Erickson says
Yes, you would add the code from your comment into your theme’s functions.php file.
Ariel says
Thanks for this Bill. Exactly what i’m looking for. And frankly, the only one i saw who wrote about a condition (if date modified is longer than a week, etc).
I’d like to ask, how would you change the conditional section if i want it to be 3 months or 6 months or older (instead of a week)?
Bill Erickson says
Great question! Change `WEEK_IN_SECONDS` to `3 * MONTH_IN_SECONDS` or `6 * MONTH_IN_SECONDS` to make it 3 months or 6 months, respectively.
Rajibul Islam says
Hi,
I am getting “Last updated on” by following codes. Will you please tell me, How can I show this last updated date after content?
//* Customize the entry meta in the entry header (requires HTML5 theme support)
add_filter( ‘genesis_post_info’, ‘sp_post_info_filter’ );
function sp_post_info_filter($post_info) {
$post_info = ‘Last Updated On [post_modified_date] by [post_author_posts_link] [post_edit]‘;
return $post_info;
}
Bill Erickson says
You’re using the
genesis_post_info
filter which runs before the post content. Change that togenesis_post_meta
to alter the metadata that appears after the post content.WEN HUI says
Hi,
Thanks for your informations,it’s useful with AVADA theme.
One question I have:
Is there a way to only display this on posts (and not on any pages)?
Thanks for any help!
Bill Erickson says
Before outputting the modified date, you could check
if( is_single() )
to ensure the code is only running on single posts.