[Hugo] Add prefix "Posts by tag" line whenever creating new tag

Hi guys, sorry the question kinda confused. But is possible that make Hugo add prefix “Post by [tag]” in title everytime i create new tag by adding to the post?

Example below is the post that i created. I have an tag(the) params call Example. So i published the post and the markdown tag is created. But when i click on the tag, in web browser the title is only show markdown. The complete title i want is “Posts by tag markdown
I want to make an “prefix” like "Posts by + [tag that i created in frontmatter] " Is possible to do it on Hugo?
Thanks

---
title: "Rich Content"
date: "2019-03-10"
summary: "A brief summary of Hugo Shortcodes"
danhmuc:
  - talkshow
tag: 
    - markdown
---

My head.html now:

{{ $title := print .Site.Title " | " .Title }}
    {{ if .IsHome }}{{ $title = .Site.Title }}{{ end }}
    <title>{{ $title }}</title>
{{ $title := print .Site.Title " | " .Title }}
{{ if .IsHome }}{{ $title = .Site.Title }}{{ end }}

{{ if eq .Kind "term" }} 
  {{ $title = printf "Posts by tag %s" .Title }}
{{ end }}
<title>{{ $title }}</title>

About Page Kind:

1 Like

Thanks you so much. One last thing, I forgot to ask, i have 2 taxonomy, tag and category.
It work with tag , but can above method also working with category too? I’m using both for my blog

You can combine it with .Data.Singular to get the taxonomy name i.e. tags/categories

{{ $title := print .Site.Title " | " .Title }}
{{ if .IsHome }}{{ $title = .Site.Title }}{{ end }}

{{ if eq .Kind "term" }} 
  {{ $title = printf "Posts by %s %s" .Data.Singular .Title }}
{{ end }}
<title>{{ $title }}</title>

More about Taxonomy Term Page Variables:

1 Like

Thanks once again.! <3. How can i close the thread with your solution btw?

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