Insert link in front matter for a single post

I am using GitHub - adityatelange/hugo-PaperMod: A fast, clean, responsive Hugo theme. theme. I want to add a hyperlink to the front matter.
My post’s sample front matter looks like below.
+++
title: Title ?
keywords : [“keyword1”,“keyword2”]
description :random description.
+++

The same front matter is rendered to HTML as title, meta descriptions and post description in HTML. I want to add a href link to this specific post description. I used the below front matter, it got rendered as normal text in the post description.

+++
title: Title ?
keywords : [“keyword1”,“keyword2”]
description :random < a href=“http://example.com”>description.
+++

The description field in front matter is rendered in many places:

In most of these, the value should be rendered as plain text.

Unless you want to override all of these templates, I suggest using a different front matter field, and then override layouts/_default/single.html.

1 Like

“Unless you want to override all of these templates, I suggest using a different front matter field, and then override layouts/_default/single.html.”

Even if I override layouts/_default/single.html, it will be still rendered as plain text, right?
Please advise on how to achieve this.

https://gohugo.io/functions/safehtml/

Thanks, this worked while running hugo locally. But when I deployed to Vercel, it again rendered as plain text with HTML tags.

How did you override the file?

  {{- if .Description }}
    <div class="post-description">
      {{ .Description | safeHTML }}
    </div>

This override rendered the href locally.

That’s not what I meant.

Did you modify a theme file, or did you override the file by placing a modified copy of it in the layouts directory in the root of your project?

Also, it looks like you are continuing to use description instead of creating a new front matter field. If you place HTML in that field, you will get undesirable effects in the other places the field is rendered. For example, the meta element in the head element will be wrong.

Thanks for notifying the location of the file. I was editing the theme file rather than making a copy in root of my project. I missed that part. It’s completed solved with safeHTML.

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