Hugo

Meta tags not displaying

I used this in my head.html,
{{ with .Title }}<title>{{ . | title }}</title>{{ end }} {{ with .Site.Params.description }}<meta name="description" content="{{ . }}">{{ end }} {{ with .Site.Params.keywords }}<meta name="keywords" content="{{ . }}">{{ end }}

and my config.toml is,

baseURL = "https://prabhatha.com/"
languageCode = "en-us"
title = "Prabhat"
theme = "Hugo- Organization Portfolio"
summaryLength = 30

[params]
description = "Prabhat, The Temple of Art is an internationally renowned artistic institution from India. The organization has created stage history with a unique blend of tradition along with sophisticated stage techniques of the present technological era."

keywords = "arts, dance, music, theatre, plays, dramas, classical arts studios, a dance studio in Bengaluru, classical dance, theatre performance, stage props arena, costumes unit, make-up, training classes, Abhinaya, dance, music, drama, yoga courses, recording studios"

author = "Balachandiran - TenSketch"

title, description and keywords don’t show up

Kindly let me know what should I change. And adding to this,

Title, description and keywords have to change dynamically for each page, What should I do for that. Will separate .md files work or can do something in the config file?

Kindly let me know

Hi @TenSketch. Moved your post to a new thread.

1 Like

@zwbetz Thanks, waiting for help on my question!

Yep, use front matter to assign your page variables. A common practice I like is using default to render values from your config if they are not present in front matter.

Read Requesting Help and share your code, I’ll take a look.

@maiki this is my repository,

Kindly let me know what should i change

Hi,

A few issues:


Make sure you are passing the context or the “dot” to your partials. In your layouts/_default/baseof.html for example:

{{ partial "head" }} => {{ partial "head" . }}

Relevant docs: https://gohugo.io/templates/partials/


As posted above, you can use page variables in the front matter of your content to have different values applied to each page. And then use a default site-wide value when it is not specified.

So, for example:

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

Relevant docs:


Extra notes:

  • You are using <meta property="og:url" content="{{.baseURL}}"> in your partials/head.html. This should be {{.Site.BaseURL}} instead.

  • content/_index.md has no front matter.

3 Likes

@pointyfar, Thanks a lot. Works fine now! :grinning:

Sharing the working code- unique titles, description, keywords, og meta tags…

<title>{{ if .Title }}{{ .Title }} | {{ end }}{{ .Site.Title }}</title>
{{ if .Params.description }}
<meta name="description" content="{{ .Params.description }}">
{{ else if .Site.Params.description }}
<meta name="description" content="{{ .Site.Params.description }}">
{{ end }}
{{ if .Params.keywords }}
<meta name="keywords" content="{{ .Params.keywords }}">
{{ else if .Site.Params.keywords }}
<meta name="keywords" content="{{ .Site.Params.keywords }}">
{{ end }}
<!-- og meta tags -->
<meta property="og:url" content="{{.Site.BaseURL}}">
<meta property="og:image" content="{{.Site.BaseURL}}images/logo2.png">
{{ if .Params.description }}
<meta property="og:description" content="{{ .Params.description }}">
{{ else if .Site.Params.description }}
<meta property="og:description" content="{{ .Site.Params.description }}">
{{ end }}
{{ if .Params.keywords }}
<meta property="og:keywords" content="{{ .Params.keywords }}">
{{ else if .Site.Params.keywords }}
<meta property="og:keywords" content="{{ .Site.Params.keywords }}">
{{ end }}

and the site link,

https://www.prabhatha.com/

2 Likes