This post shows how to make affiliate disclosure configurable per post in the Hugo theme PaperMod.

On this blog, I used to write the disclosure directly in the article body when disclosure was required. However, copying and pasting the text every time was a hassle, so I made it easy to configure with an article parameter.

Environment

  • Windows 11 / Git Bash
  • Hugo v0.164.0 / works with the standard build as well
  • PaperMod v8.0 / using the latest commit at the time of writing
$ hugo version
hugo v0.164.0-ce2470e7012b5ab5fc4e10ebe4027e9f8d9e00dc+extended windows/amd64 BuildDate=2026-07-06T16:39:30Z VendorInfo=gohugoio

$ cd themes/PaperMod && git log -1 --oneline
154d006 (HEAD -> master, origin/master, origin/HEAD) style(post-single): adjust padding for details summary element

Installation steps

1. Create a custom layout

Copy themes/PaperMod/layouts/single.html to layouts/single.html.

2. Add affiliate disclosure rendering

Add the highlighted section and affiliate disclosure rendering to the custom layout. This site handles Japanese and English, so it uses i18n.

Place the display below the publication date and language switch UI so readers can recognize that the article contains affiliate links before they read the body.

By the way, template comments do not remain in the final HTML output, so it is fine to keep them as markers for the changed section.

    ...
    <div class="post-meta">
      {{- partial "post_meta.html" . -}}
      {{- partial "translation_list.html" . -}}
      {{- partial "edit_post.html" . -}}
      {{- partial "post_canonical.html" . -}}
    </div>

    <!-- Affiliate Disclosure -->
    {{- if .Params.affiliate }}
    <div style="color: var(--primary); font-size: 0.85rem; margin-top: 10px;">
      {{- i18n "affiliate_disclosure" }}
    </div>
    {{- end }}
    ...

3. Add affiliate disclosure text to the language files

i18n/en.yaml

- id: affiliate_disclosure
  translation: "Note: Links may earn me a commission."

i18n/ja.yaml

- id: affiliate_disclosure
  translation: "※ 本記事にはアフィリエイトリンクが含まれます。"

4. Add affiliate as a default parameter for new articles

At this point, if you add affiliate: true to an article’s frontmatter, the affiliate disclosure text will be displayed for that article. However, if the parameter is missing when creating a new article, it is easy to forget how to display it, so add it now.

Add the parameter to the frontmatter of archetypes/default.md. On this blog, affiliate articles are less common, so the default is set to false.

---
...
affiliate: false
---

5. Verify

Start the development server with hugo server and verify.

If the affiliate disclosure text is displayed on an article with affiliate: true, you are done.