# Automatic Internal Linking based on Keywords

**URL:** <https://discourse.gohugo.io/t/automatic-internal-linking-based-on-keywords/30615>\
**Category:** support\
**Created:** [January 13, 2021, 1:57pm UTC](https://discourse.gohugo.io/t/automatic-internal-linking-based-on-keywords/30615 "2021-01-13T13:57:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![heisenburger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/heisenburger/32/13296_2.png) [@heisenburger](https://discourse.gohugo.io/u/heisenburger)\
**Post date:** [January 13, 2021, 1:57pm UTC](https://discourse.gohugo.io/t/automatic-internal-linking-based-on-keywords/30615/1 "2021-01-13T13:57:21Z")

</div>

Hi,

I am pretty new to Hugo and would like to learn more about building sites with it. Currently I am wondering if I am able to define in a Markdown file for example `Internal-Links: {keyword: kw1, url: /page1}, {keyword: kw2, url: /page2 etc.`, have Hugo when building the site check the content body of the Markdown file for those keywords and have those found keywords converted to links to other pages. The goal is trying to have a somewhat automatic internal linking of blog pages based on defined keywords/tags and have hugo automatically inject the links into the content.

Thank you for any help and replies - highly appreciated.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [January 13, 2021, 2:39pm UTC](https://discourse.gohugo.io/t/automatic-internal-linking-based-on-keywords/30615/2 "2021-01-13T14:39:02Z")

</div>

Not entirely sure about how you could configure the _automatic_ part of your question.

Have a look at: [Links and Cross References | Hugo](https://gohugo.io/content-management/cross-references/)

Also the function [relref | Hugo](https://gohugo.io/functions/relref/#readout)

A hacky workflow that comes to mind, would be to:

- Store an array of these keywords in a parameter of the project’s [config](https://gohugo.io/getting-started/configuration/#configuration-file).
- Use the [`replace`](https://gohugo.io/functions/replace/#readout) or [`replaceRE`](https://gohugo.io/functions/replacere/#readout) functions to check up the `.Content` of [Single Pages](https://gohugo.io/templates/single-page-templates/#readout)
- When encountered, the keywords will be wrapped in HTML links markup, that will point to a [Related Content File](https://gohugo.io/content-management/related/#readout).
- However since there may be more than one Related Content links you would most likely need to pick a single one (at random) by piping the Related Content links with the [`uniq`](https://gohugo.io/functions/uniq/#readout) function.

It would be quite complicated even for me to put the above together and I am only spitballing here.

I don’t think that as beginner you want to follow that path, also because depending on a project’s size the above may slow down the project build time (or it may not).

Perhaps others can offer more informed suggestions to your question.

---

<div class="post-metadata">

**Author:** ![heisenburger](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/heisenburger/32/13296_2.png) [@heisenburger](https://discourse.gohugo.io/u/heisenburger)\
**Post date:** [January 13, 2021, 3:27pm UTC](https://discourse.gohugo.io/t/automatic-internal-linking-based-on-keywords/30615/3 "2021-01-13T15:27:24Z")

</div>

@alexandros thank you very much for taking the time to answer my question, highly appreciated. `relref` is a good start indeed to parse the permalinks. Currently I was thinking to use the [replaceRE](https://gohugo.io/functions/replacere/) function for finding the keywords and replace them with the URL and fund the regex/replace pattern via the template variables from the index.md
