Adding Custom Meta Tags to Hugo

PUBLISHED ON SEP 21, 2019 — BLOGGING, HUGO

After reading about the Mozilla Foundation and Coil’s announcement, I decided I wanted to try an experiment and add a Coil micropayment meta tag to my blog. I couldn’t find an obvious way to do this with Hugo or much information about it in their docs. I first tried just adding the key-value pair to my config.toml.

# config.toml

monetization = "$coil.xrptipbot.com/zP3gu5RkRVSdjBhe_fu3XA"

The values didn’t end up in the <head> tag on my site, though. Then, after skimming through Hugo’s discussion forum, I hit upon the idea to check out the theme’s header.html partial. I added a check and a spot for the monetization meta parameter on my fork:

<!-- themes/hugo-goa/layouts/partials/header.html -->

{{ with .Site.Params.meta.monetization }}<meta name="monetization" content="{{.}}">{{ end }}

Now the value is populated when I build my site!

A more long-term solution would be iterate through the values in config.toml’s [params.meta] section, and populate the site’s meta tags based on those key-value pairs.

TAGS: META