Show last updated date in Blogger posts

Published on September 19, 2016 . Updated on: -
Although this is not the kind of post for this blog, I decided to write about this because there are opinions saying it is impossible to show updated date in Blogger posts. Blogger offers support only for the date when a post is published. You can, of course, edit the post and change published date, but that is not what most people want.

The method that follows is completely automatic and it will print the last date when you used the post editor on the specific post. It makes use of data stored in blog feed, because, although there is no tag for updated date in Blogger (something similar to published date tag data:post.timestamp), the updated date is stored in your blog feed. I first noticed this when I registered my blog on Tapatalk and noticed that updated posts appeared on top of the list.

Show last updated date in Blogger posts


Of course, you must have a Blogger blog. You must enable the feed by going to Settings, Other, Site Feed. I'm using Until Jump break setting, but I guess everything will work except None. Your blog must also use jQuery. Somewhere in your template you should have in the head section (or add if there isn't) the line:
<script src='' type='text/javascript'/>
It's OK to use a different jQuery version.

The script

Here is the script originally written by Yu-Jie Lin that will fetch the feed as JSON, parse it, get the date and display it.
<b>Updated on:</b> <span id='updatedateinfo'>-</span>

<script async='async'>
var postID = "<>";
jQuery.getJSON('' + postID + '?alt=json-in-script&callback=?', function(data) {
    var entry = data.entry;
    var dateu = new Date(entry.updated.$t);
    var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
  document.getElementById("updatedateinfo").innerHTML = months[dateu.getMonth()] + " " + dateu.getDate() + ", " + dateu.getFullYear();
  document.getElementById("updatedateinfo").title = dateu;
The script will show the date inside a span element with id=updatedateinfo. Don't forget to adjust the URL with the correct blog ID.

You can improve it if you want. For example, you can compare published date with updated date and display updated date only if it is different.

This method has one big disadvantage. You can't use structured data tags for the span element (i.e. itemprop=dateModified) because search engines will not run the Javascript code and will not index updated date.

From the same category:

Share this page:


Post a Comment

Please read the comments policy before posting.