# Customizing Markdown Links in Hugo

**URL:** <https://discourse.gohugo.io/t/customizing-markdown-links-in-hugo/38628>\
**Category:** tips & tricks\
**Created:** [May 15, 2022, 4:39am UTC](https://discourse.gohugo.io/t/customizing-markdown-links-in-hugo/38628 "2022-05-15T04:39:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![techmagus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/techmagus/32/16997_2.png) [@techmagus](https://discourse.gohugo.io/u/techmagus)\
**Post date:** [May 15, 2022, 4:39am UTC](https://discourse.gohugo.io/t/customizing-markdown-links-in-hugo/38628/1 "2022-05-15T04:39:05Z")

</div>

I would like to share what I did to add cross reference support and link icons in regular Markdown links with the use of Hugo’s render hooks.

What I have achieved so far are the following:

- I no longer need to use `ref` and `relref`
- Use the content’s title
- Multilingual support
- Supports the regular Markdown text and title
- URI #fragment support
- Link icons

There are three Markdown link formats I have not figured out (included in the article) but so far as to what I need, everything works fine.

It’s a bit long, so I have it here on my blog: [How To Customize Markdown Links in Hugo](https://im.youronly.one/techmagus/codebits/how-to-customize-markdown-links-hugo-2022135/).

Enjoy. Shalom!

---

<div class="post-metadata">

**Author:** ![lkhrs](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/lkhrs/32/22287_2.png) [@lkhrs](https://discourse.gohugo.io/u/lkhrs)\
**Post date:** [May 15, 2022, 4:45am UTC](https://discourse.gohugo.io/t/customizing-markdown-links-in-hugo/38628/2 "2022-05-15T04:45:11Z")

</div>

Link icons for different protocols is super cool, going to borrow this for my blog 👀

---

<div class="post-metadata">

**Author:** ![bwintx](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bwintx/32/10450_2.png) [@bwintx](https://discourse.gohugo.io/u/bwintx)\
**Post date:** [May 15, 2022, 2:40pm UTC](https://discourse.gohugo.io/t/customizing-markdown-links-in-hugo/38628/3 "2022-05-15T14:40:11Z")

</div>

Very nice! One note: copied/pasted as-is, the proposed code produces an error. In this part…

```nohighlight
{{ with or .Title $internal.LinkTitle .Test }}

```

… it should say `.Text` rather than `.Test` — otherwise, `hugo server` throws an error (part of which is shown below), then quits:

```bash
can't evaluate field Test in type goldmark.linkContext

```

---

<div class="post-metadata">

**Author:** ![techmagus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/techmagus/32/16997_2.png) [@techmagus](https://discourse.gohugo.io/u/techmagus)\
**Post date:** [May 15, 2022, 7:15pm UTC](https://discourse.gohugo.io/t/customizing-markdown-links-in-hugo/38628/4 "2022-05-15T19:15:54Z")

</div>

@bwintx Thank you for catching that! Fixed! 🙂

---

<div class="post-metadata">

**Author:** ![ju52](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ju52/32/6749_2.png) [@ju52](https://discourse.gohugo.io/u/ju52)\
**Post date:** [May 16, 2022, 8:28am UTC](https://discourse.gohugo.io/t/customizing-markdown-links-in-hugo/38628/5 "2022-05-16T08:28:45Z")

</div>

found same error and fixed it for me.  
Nice to drop ref and relref shortcodes 🤩

Had it in some posts and removed now - looks more nice  
Thanks

---

<div class="post-metadata">

**Author:** ![tut](https://avatars.discourse-cdn.com/v4/letter/t/e95f7d/32.png) [@tut](https://discourse.gohugo.io/u/tut)\
**Post date:** [May 16, 2022, 1:56pm UTC](https://discourse.gohugo.io/t/customizing-markdown-links-in-hugo/38628/6 "2022-05-16T13:56:07Z")

</div>

Can this work with [this](https://discourse.gohugo.io/t/link-cloaker-option-with-hugo/38231/2)?

---

<div class="post-metadata">

**Author:** ![techmagus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/techmagus/32/16997_2.png) [@techmagus](https://discourse.gohugo.io/u/techmagus)\
**Post date:** [May 16, 2022, 9:07pm UTC](https://discourse.gohugo.io/t/customizing-markdown-links-in-hugo/38628/7 "2022-05-16T21:07:23Z")

</div>

> [@tut](#):
>
> Can this work with [this](https://discourse.gohugo.io/t/link-cloaker-option-with-hugo/38231/2)?

Hmm… not sure what the sample repo was (no longer available) – I mean the ‘how’ – but as per the OP in the thread, no, the codes I shared doesn’t support masking. It’s only for adding ref/relref functionality in regular markdown links (`[text](https://example.com "Title")`) and link icons.
