HTML Author meta tags in Hugo - A short guide

Defining the author of the html document can be useful if your Hugo site is a blog and you want to attribute the content of the current html page to that person.

A HTML Author meta tag looks like this:

 <meta name="author" content="Luke Morgan" />

If you want this to be dynamic then here is a simple way to achieve this. Firstly, in your site’s config.toml file, define some author params like this:

[params]
  description = 'A blog about building websites with Hugo and everything in between'
  useCover = true
  [[params.author]]
    name = "Luke Morgan" 
    description = "Blogging about building hugo sites whilst learning to build hugo sites"

Now really for the meta tag, you only need the name, so make sure you can reference the name you want for the params.

In the layout file or partial that is responsible for handling the <head> content - add this:

  {{ range .Site.Params.author -}}
      <meta name="author" content="{{ .name | default " Jeffrey Lebowski" }}" />
  {{ end -}}

Now obviously you’ll only need to use the range function if your author param is a map like mine. But whichever way you do decide to set it up, i recommend taking note of the - charachter at the end of the opnening and closing logic to check for the author param. This will keep the whitespace tidy in your document when it does get output.

Read more about whitespace in Hugo templates here