arrow_back
Back

Hugo taxonomies: tags, categories, terms layouts, and disabling

Andrew Dorokhov Andrew Dorokhov schedule 2 min read
menu_book Table of Contents

Hugo supports categories and tags out of the box and can generate list pages for them automatically. Add them to front matter:

categories:
- Personal
- Thoughts
tags:
- software
- html

Then visit /tags and /categories (using your default list layout unless you customize it).

Terms vs taxonomy

/tags lists taxonomy terms. A single tag page (e.g. /tags/software) is the taxonomy listing for that term. Layout names depend on which view you customize.

Terms list layout

Create layouts/_default/tag.terms.html (or under your theme):

{{ define "main" }}

  <h2>{{ .Title }}</h2>

  {{ .Content }}

  {{ range .Data.Terms.Alphabetical }}
  <p class="tag">
    <a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a>
    <span class="count">({{ .Count }})</span>
  </p>
  {{ end }}

{{ end }}

.Data.Terms is the collection of all tags for the site.

Single tag layout

Create layouts/_default/tags.html and reuse the same pattern as your list layout to list matching pages.

Linking tags from a post

<p>
  Posted {{ .Date.Format "January 2, 2006" }}
  <span class="tags">
    in
    {{ range .Params.tags }}
      <a class="tag" href="/tags/{{ . | urlize }}">{{ . }}</a>
    {{ end }}
  </span>
</p>

urlize makes the tag URL-safe (spaces and special characters).

Content shown via {{ .Content }} on /tags comes from content/tags/_index.md when present.

Disabling taxonomies

Redefine [taxonomies] to drop tags or categories. Defining the section replaces the defaults, so keep what you still need:

[taxonomies]
category = "categories"

Tags only:

[taxonomies]
tag = "tags"

Disable taxonomies entirely:

disableKinds = ['taxonomy', 'term']
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward