Most websites have the current year displayed next to the copyright notice in the footer. But having to manually update it year after year isn’t ideal, no?
Fortunately, programming languages, frameworks, SSGs, and such, usually provide an easy way to handle dates, especially when it’s something simple like displaying the current year automatically.
If you’re using Hugo for your website or blog, as I am, here’s how to do it.
Automatically Update the Footer Copyright Year in Hugo
Automatically displaying the current year in Hugo is easily done using one of its built-in functions.
All you have to do is to go to your footer.html
partial, or wherever your footer’s HTML code is, and use one of these two codes based on the “now” function:
now.Format "2006"
now.Year
So, the HTML code should look like this:
<p>
<small>Copyright © {{ now.Format "2006" }}</small>
</p>
Or, with the alternative:
<p>
<small>Copyright © {{ now.Year }}</small>
</p>
Note that with this code now.Format "2006"
, you don’t have to change the year between the quotes. That handles the format and reference time (2006) that many programming languages use, if not all. From what I understand, it has something to do with ISO 8601.
Of course, you can use this function to display the current year wherever you want on your website, not just the copyright footer.
That’s a Wrap
I hope you found the tutorial useful.
If some info is outdated or incorrect, or you have anything to add, say or ask, please contact me via Twitter or email.
Looking for a modern & optimized presentation website?
Hire me on Fiverr