Meta description attribute

Up and running with my self hosted blog using the hugo uno theme and all looks good.

To develop this a little further I want to add a meta description to each page, but it’s not happening!
I’ve read the section on Front Matter, and added the description attribute to the respective post.md

+++
date = "2016-08-09T21:33:04+01:00"
draft = false
title = "Reconfiguring the TalkTalk DSL-3680 Router to work with a home network"
description = "If using talktalk router DSL-3680 for a home network or to serve a website etc, etc,etc"
tags = [ "talktalk", "DSL3680", "router", "admin page" ]
+++

…and expected the meta ‘description’ to be added after a re-compile, but looking at the source of the published page, the meta description hasn’t been added.
Am I doing something wrong?

This is my URL

Paul

Make sure to include a meta name=“description” line in the head of your html file… Depending on the structure of your theme, this is managed either on index.html or on a partial called within your index.html (sth. like “head.html” or so).
I just had a quick look into uno theme, it’s handled in the partial “head.html”

There you can place something like:

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

Edit: BTW, in order to optimize your site for SEO purposes (even though meta tags are by far not as important anymore as they used to be), I recommend using a more complex structure in order to go sure that every page has the best meta description it can get. In my case, for example, I use the following:

{{ if .Description }}
<meta name="description" content="{{ .Description }}">
{{ else if .IsPage }}
<meta name="description" content="{{ .Summary | plainify }}">
{{ else if eq .URL “/blog/” }}
<meta name="description" content="Lass dich inspirieren - mit einzigartigen Blog-Posts und Videos zu Yoga, Reisen, Mind & Meditation, Gesundheit und mehr. - Get inspired & share the spirit!">
{{ else }}
<meta name="description" content="Yoga-Unterricht auf Spendenbasis. Inspirierender Blog & Videos über Yoga, Reisen, Mind & Meditation, Gesundheit & mehr. - Get inspired & share the spirit!">
{{ end }}

It’s not perfect yet, but might give you an idea what I’m talking about. (However, as your site structure is not as complex as mine, you will probably just need a simple if else.)

4 Likes

I’ll revisit your ‘complex structure’ when I get a bit more familiar with Hugo, but for now, I’ll stick with adding the meta in the partial “head.html”, I’ve just tried it, and it works great - thank you.

Paul

@Paul_Reed Unless you want to use the built-in summary ability on single pages, you can simplify the above using default. {{.Description | default .Site.Params.SiteDescription}}

Then just add your .SiteDescription to your params in your config

4 Likes

@rdwatters, I’ll stick with the ‘single page’ option for now, but thanks for the suggestion :sunny:
I’m still finding my feet here, so things may (probably will!) change.

Paul

@inspiritana
@rdwatters
@Paul_Reed

Please take a look at my version of meta description logic.

File: baseof.html

{{ $description := "" }}
{{ if .IsPage }}
  {{ if .Params.Description }}
    {{ $description = .Params.Description }}
  {{ else }}
    {{ $description = .Summary }}
  {{ end }}

{{ else if .Params.Description }}
  {{ $description = .Params.Description }}

{{ else }}
  {{ $description = .Site.Params.Description }}

{{ end }}

Thanks,
Faizan Vahevaria
CEO, Fatah Digital
Hugo Developer with 3 years of Experience

2 Likes

Seems like using default would make this so much shorter and easier to reason about, IMHO.

2 Likes