Hey everyone, I am going through the same problem. By default, Hugo generates the following links with the translationKey being the same in both files:
a) What’s the problem?
b) What template code is generating the link elements?
c) How is the site configured?
d) What does the front matter look like?
e) etc.
You are more likely to receive a prompt and accurate response if you post a link to your project’s Git repository.
Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.
If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.
Sure. I implemented the following code in layouts/partials/head.html:
{{- if .IsTranslated -}}
{{ range .AllTranslations }}
{{- if eq .Language.Lang "en" -}}
<link rel="alternate" hreflang="x-default" href="{{ .Permalink }}" />
{{- end -}}
<link rel="alternate" hreflang="{{ .Language.Lang }}" href="{{ .Permalink }}" />
{{- end -}}
{{ end }}
I also adapted layouts/_default/headof.html with:
<head>
<!-- Fix for when x-default is not English: https://dariusz.wieckiewicz.org/en/setting-hreflang-and-x-default-on-multilingual-site/ -->
{{ partial "head.html" . }}
<!-- head (don't cache it) -->
{{ partial "essentials/head.html" . }}
<!-- style (always cache it) -->
{{ partialCached "essentials/style.html" . }}
</head>
However, the default rel=alternate are still being generated, would love your help in getting rid of them and only sticking to the overwritten ones in layouts/partials/head.html.