How to link to tags from markdown

Hi,
I’m totally new to Hugo and stumbled upon this post as a result of a web search for “hugo link to tag”. However, what I meant was something different: how can I link to / reference a tag (and a category) in a markdown file (blog post / article / page / …)? Like if I want to say something like “… see my articles under the tag xyz …” where xyz would then be the actual link to that tag when the pages get rendered by Hugo.
:flushed:
I hope it’s understandable?!
Thanks so much!
Cheers,
Stefan.

Hi there,

The topic you were replying to is several years old now and is a different question to the original. I’ve opened a new topic for you.

1 Like

Is your question about how to form hyperlinks in markdown?

see my articles filed under [xyz](https://example.org/tags/xyz)

Produces: see my articles filed under xyz

1 Like

Nope, that I know.
I was wondering how to link to a tag, what’s the URL for a tag.
Your example helped and it works! Thank you! :slightly_smiling_face:

I was just reading about the ref and relref shortcodes here and thought that when linking to internal pages there might be a shortcode for linking to tags and categories as well.

But apparently there’s not and a link to a self-invented tag is just /tags/<mytag>. Hurray! :smiley:
And a link to a category works with /categories/<mycategory>. Nice!

Which brings me to a related question (should I open a new topic for it?): what URL would list all the posts that are in category cat1 and have the tag tag1? :flushed:

Hugo does not generate such a page.

1 Like

It’s an old topic, but comes up in web searches, so allow me to post my solution using a custom shortcode.

layout/shortcodes/tagref.html

{{- $tag_page := site.GetPage (printf "tags/%s" (.Get 0)) -}}
{{- if $tag_page -}}
  {{- $tag_page.RelPermalink -}}
{{- else -}}
  {{ errorf "No such tag: %s" (.Get 0) }}
{{- end -}}

Usage in a Markdown content file:

see my articles filed under [xyz]({{% tagref "xyz" %}})

The advantage over hardcoding /tags/xyz/ is that you can change the URL structure later, and that you get an error message in case the named tag does not exist.

2 Likes