Show modification time on GoHugo posts
I want to be able to show the last time I updated the content of a file, but I don’t want anything fancy in charge of doing so. I want something simple and easy. Something I won’t need much time to maintain or modify as I please with no fuzz. Here I show you how I accomplish this by use the front matter to manually specify the updated time of any post.
The first thing we will need is to create a template for any post under layout/_default/single.html
. It’s content should be something similar to what’s on snippet below; it defines that the custom changes belong to the main
area, adds the title as a header, and also add the original publication date of the post. Note the Updated on
will be displayed only in case the last modification (Lastmod
) is different than the publication date (Date
).
1{{ define "main" }}
2 <article>
3 <h1>{{ .Title }}</h1>
4 <div style="margin-bottom:0.5em; color:#888; font-size:0.95em;">
5 Published on {{ .Date.Format "2006-01-02" }}
6 {{ if ne .Lastmod.Unix .Date.Unix }}
7 | Updated on {{ .Lastmod.Format "2006-01-02" }}
8 {{ end }}
9 </div>
10 {{ .Content }}
11 </article>
12{{ end }}
To set the last modification date of a post you will need to add the lastmod method in the front matter. For example, here I have the front matter for the TIL GoHugo callouts. I add the date: 2025-0615...
and the lastmod: 2025-06-19...
.
1---
2title: GoHugo callouts
3date: 2025-06-15T23:02:20Z
4lastmod: 2025-06-19T21:00:00Z
5draft: false
6tags:
7- hugo
8- go-hugo
9- callouts
10---
By doing so, the page renders both published and updated on dates as shown in the screenshot below. With this, we are now able to show to people whether or not a page has been updated or if its been untouched for years.