Meta Description for Posts (Minimal Bootstrap Theme)


I recently started using Hugo with the Minimal Bootstrap Theme and noticed it’s using the same description for each post.
In the head.html file I found the following regarding the description:

  {{ with .Site.Params.description }}
  <meta name="description" content="{{ . }}">
  {{ end }}

So the theme uses the site configuration for every post.
I tried to edit it so that if a post has a “description” set it should use the posts description and if there is no description set it should use the default one (site params) instead.

Unfortunately I could not get it to work. Is there a way to set it up like this?


<meta name="description" content="{{ .Param "description" }}">

Thank you, I actually got it to work with the following:

  {{ if isset .Params "description" }}
  <meta name="description" content="{{ .Description }}" />
  {{ else }}
  <meta name="description" content="{{ $.Site.Params.description }}" />
  {{ end }}

I don’t know if this is the correct way to do it but it works pretty well.

1 Like