Change taxonomy list page html title?

How can I have my index page show a different html title than the tag title?

The theme by default shows the .Title variable as the html page <title> and also uses .Title as the h1 header value.

In tags/mytag/_index.md, I created a new frontmatter variable and edited the /layouts/tags/list.html layout so I could display an h1 of my choosing (as suggested in Change taxonomy list page title?) But this still doesn’t change the html page title as that is defined in the base template as coming from .Title.

I can create another frontmatter variable such as pageTitle and override the base template to check for it and display it if present. Effectively I would have three title variables:

  1. title for the tag name itself
  2. headerTitle for the page header text
  3. pageTitle for the html page <title>

Just wondering if this would be the Hugo way to do it

Add content/tags/tagname/_index.md for the tag tagname and work in the frontmatter with whatever you want like:

---
title: "Something completely different"
---

If you want to crawl deeper into the rabbit hole: this is the place where you can add content to list pages for single tags. Use it as a page bundle and you can add images and other media to the folder.

1 Like

I’m starting to see how it works and it’s a nice structure and symmetry, although as I mentioned in my previous thread the behavior of the title overriding the tag name was a little unexpected. My goal originally was to simply change the title for the list page for a single tag.

It does accomplish that but also, using your example, if a single post was tagged with tagname, and the post listed its tags, as single posts often do, the post would show Something completely different as the tag instead of tagname. Also it seems as if the original tagname is hidden from the hugo system (i.e. not available as a variable value… if I’m understanding how hugo works)

I am actually working on the same issue at the moment. I added a custom slug to my taxonomy but the tags you can retrieve from a page object are only strings, not taxonomy objects with the whole content and all the links which I customized were wrong (Hugo docs also just print the tagname in a “manual” way).

So what I did was this:

getTag.html

{{ with site.GetPage (printf "/tags/%s" .) -}}
  <a href="{{ .RelPermalink }}"  title='All pages tagged with "{{ .Title }}"' rel="tag">{{ .Title }}</a>
{{- end }}

content.html

{{ partialCached "getTag.html" $e "tags" $e }}

where $e is the current tagname. This will retrieve each tag’s data once ("tags" $e) and hands you all data you need to set it up properly. The $e is a string with the tagname in my range.

I would assume you find a way to add params to the frontmatter of your custom tag to check against and fix your issue.

There are some hard coded things in there still like “tags” as path/taxonomy-name but I think you get the way…

1 Like