Dynamic Copyright Year when using Hugo

GeekThis remains completely ad-free with zero trackers for your convenience and privacy. If you would like to support the site, please consider giving a small contribution at Buy Me a Coffee.

After the New Year I always check the footer on websites to see which sites forgot to update the copyright year. If you have a dynamic site, this shouldn’t be an issue at all since you can easily program your site to show the current year. I’ve been using Hugo for a few months to generate my static websites and wanted an easier way to update the copyright year, or better yet, not have to update the copyright year.

Below is a quick tutorial on how I have the copyright year for my sites that use Hugo update without having to change any configuration files manually. Because Hugo is a static site generator, you will still need to generate and upload the new site each year, but you don’t have to worry about remembering to change the copyright year every year. Whenever you make your first change of the year, the copyright will update along with the modifications.

To set your Hugo site to update the copyright year without having to remember to do it manually each year, use the following steps.

  1. Open the Hugo configuration file (config.toml) and find the line for the copyright text.
  2. Modify the value for copyright to show the placeholder text {year} instead of the actual year.
  3. Open the template file that displays the copyright. This is usually in a file called footer.html. If you are unable to find what file is used to display the copyright text, use findstr or grep to search for the string .Site.Copyright.
  4. Replace the code to display the copyright text, which is usually {{ .Site.Copyright }} with {{ replace .Site.Copyright "{year}" now.Year }}.
baseURL = "http://www.example.com/"
title = "Example Site"
copyright = "Copyright 2007-{year} Example LLC. All rights reserved."
<footer>
	<span class="copyright">
		{{ replace .Site.Copyright "{year}" now.Year }}
	</span>
</footer>

The above code is replacing all instances of the text {year} within the variable .Site.Copyright with the current year. We can get the current year by using the now.Year variable from the now function.

Other Methods

There are other methods to keep the copyright year text consistent with the current year, such as using JavaScript. With JavaScript you would grab the footer text and replace a placeholder with the current year (similar to what we do above). I don’t recommend using JavaScript to modify the copyright year of your site since it can lead to cached versions of your site showing the incorrect year along with showing the wrong year for users who have JavaScript disabled.

Related Posts

Generating Random Numbers, Strings, and more in Hugo

Create random numbers, random strings, fetch random items in slices, and generate repeatable seeds within the Hugo static site generator.

Hugo Footnotes and Citations

Add footnotes, citations, and references to your Hugo posts with this simple technique. Give your articles more credibility and improve your posts by making them more informative.

How to Separately Handle Multiple Website Deployments

Learn how to configure your computer to run multiple website deployments with rsync and multiple Linux accounts.

Build Script for Hugo Websites

A basic bash build script for Hugo websites to compress images, JavaScript files, and CSS before releasing your website to the public. Keeps a copy of uncompressed assets while easily compressing all files before uploading your website.