Change taxonomy list page title?

I’m using the built-in tags taxonomy.

I have a tag Best seller

This creates a listing page (i.e. list of all content with that tag) example.com/tags/best-seller with the display title of “Best Seller”. I wanted to change the title/header display of the listing page to something like “New York Times Best Sellers”.

So I created the following file and added a title field “New York Times Best Sellers”
mysite/content/tags/best-seller/_index.md

This did change the title on the tag list page, but had the unintended side effect of also changing the tag text from Best Seller to New York Times Best Sellers on single pages where the tag is displayed

The relevant section of the theme that prints out the tags:

 <ul class="post-tags">
    {{- range ($.GetTerms "tags") }}
    <li><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></li>
    {{- end }}
  </ul>

Is there a way to keep the original tag name while still changing the title on the tag’s listing page?

Use a custom parameter in said _index.md like pre = "New York"and then in the template use:

{{ with .Params.pre }}{{ . }} {{ end }}{{ .LinkTitle }}

The above will append the string New York to the value of .LinkTitle if .Params.pre is found in the front matter of a content file.

If you want to completely override the LinkTitle rendering in your Tags list with .Params.pre, then you can adapt the above in a condition like:

{{ with }}...{{ else }}...{{ end }}
1 Like

Are the original tag values “lost” to hugo?

My content files still have the original tag values:

tags: ["Best Seller"]

Is there no way to retrieve that value?

I think I misunderstood you. Basically you’re saying instead of using the Title field in the _index.md file, create a new field that will be the title but won’t affect the tag display elsewhere in Hugo?

IMHO, it seems a little strange that Hugo behaves this way with the tag names

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.