diff options
author | Tina <feministclickback@mail36.net> | 2020-05-08 18:20:12 +0300 |
---|---|---|
committer | Tina <feministclickback@mail36.net> | 2020-05-08 18:20:12 +0300 |
commit | 8ad42947c8f8449a3695cd2019c9c6addfd469f4 (patch) | |
tree | 3fb5e45546869ddaa37f1c3243ae4fe7a0fdfb6c | |
parent | 649cb510156d9869c40405ae6b3a2709c2f8d568 (diff) |
Add hreflang-tags to <head>
This adds hreflang-tags to <head>.
See https://moz.com/learn/seo/hreflang-tag
Hugo stores translations in .Translations and links translations,
if the content directory is set up properly.
See https://regisphilibert.com/blog/2018/08/hugo-multilingual-part-1-managing-content-translation/
This code checks if the page is translated, then creates hreflang tags
for all translated versions including the current page. This is
important because hreflang-tags need to be self-referencing (search
engines need to know all available versions).
-rw-r--r-- | layouts/partials/head.html | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 8d0b97f..e617b43 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -6,6 +6,12 @@ <title>{{ $.Site.Title }} - {{ .Title }}</title> <link rel="icon" href="{{ $.Site.BaseURL }}{{ $.Site.Params.favicon }}" /> <meta name="description" content="{{ $.Site.Params.description }}" /> + + {{ if .IsTranslated }} + {{ range .AllTranslations }} + <link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ .Permalink }}" title="{{ .Language.LanguageName }}"> + {{ end }} + {{ end }} {{ hugo.Generator }} |