Insert Live HTML Timestamp in WordPress Posts

Insert Live HTML Timestamp in WordPress Posts

I've been quite busy lately and didn't want to update my blog resources every day. So I decided to insert a fake "last updated" timestamp in my posts — without hours/minutes/seconds, accurate only to the day.

This way, when visitors open my blog, they see the resource was "updated today". It's a bit of a trick, but it successfully avoids 99% of readers asking me when new content will be out. Haha, I'm just lazy!

I searched for a long time to find a code snippet that works perfectly in WordPress posts without errors and displays correctly.

Here's the code:

var date = new Date();
document.write("Resource updated on: " + date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate());