Hooks
Empty templates in the theme that you fill with HTML of your own, on every page.
| File in your site | Where it goes |
|---|---|
layouts/_partials/hooks/head-end.html | the end of <head>: analytics, a font, a script that must run early |
layouts/_partials/hooks/body-end.html | the end of <body>: a script, comments, a notice |
The theme has empty versions; yours replace them. The display card on the home page is a hook too, and your own CSS the hook for styles.
Analytics
A privacy-friendly counter like GoatCounter (opens in a new tab) or Plausible (opens in a new tab), only on the published site, not while you write:
{{ if hugo.IsProduction }}
<script data-goatcounter="https://jane.goatcounter.com/count" async src="//gc.zgo.at/count.js"></script>
{{ end }}Comments
giscus (opens in a new tab) keeps comments in your GitHub repository’s Discussions. Configure it on its site, then paste the script it gives you, only on posts:
{{ if and .IsPage .Section }}
<section class="wrapper" style="margin-block-end: 3rem">
<script src="https://giscus.app/client.js"
data-repo="jane/my-site" data-repo-id="…" data-category="Comments" data-category-id="…"
data-mapping="pathname" data-theme="preferred_color_scheme"
crossorigin="anonymous" async></script>
</section>
{{ end }}.IsPage .Section is true for a post in a section, not for the home page or About. Hooks are Hugo templates, so
everything in Hugo’s template docs (opens in a new tab) works in them.