Shopify Liquid Code to Add Last Modified/Updated Date
Most Shopify sites show the "Published" date on blog posts, and it's not always clear how to add the "Updated" or "Modified" date to your content instead.
Here's a code snippet I like to use for this:
Last updated <time pubdate datetime="{{ article.updated_at| date: '%Y-%m-%dT%H:%M:%SZ' }}">{{ article.updated_at| date: format: 'date' }}</time>
Simply modify your main-article.liquid file (or similar), look for the section in the code with the post date, and plop this code in there.
Some people choose to show the updated date instead of the publish date, like myself. Others like to show both and let Google pick which one they want to use. I've discussed and pros and cons of both in a blog post here, which includes a handful of quotes from other SEO experts I spoke with on this subject.
You can change the output of how the date looks by tweaking this part:
%Y-%m-%dT%H:%M:%SZ
Here are a few other variations, if you want the date to be displayed in a different format:
%Y-%m-%d
Output: 2024-06-20
%m/%d/%Y
Output: 06/20/2024
%d-%m-%Y
Output: 20-06-2024
%B %d, %Y
Output: June 20, 2024
%d %B %Y
Output: 20 June 2024
%B %-d, %Y
Output: June 20th, 2024
%d/%m/%Y
Output: 20/06/2024
%b %d, %Y
Output: Jun 20, 2024
%Y %B %d
Output: 2024 June 20
Please leave me a comment if this helped you or if you have any questions for me!
November 06, 2024
I've tried changing the date format and it works great! 😊 But what do you think about showing both the publish and updated dates?
December 10, 2024
Hey Jamaal! It's really great to hear that the change in date format is working well for you!
You should definitely think about showing both the published and updated dates. You could easily add another field in your code to also track the date it was originally published. I've noticed that many people do this because it helps with transparency and keeps readers informed.
Go ahead and try it out and please feel free to let me know if you need any more details! 😊