When I checked my site with Google Webmaster Tools, I saw a warn about a missing hreflang
tag.
I have a one-page website which is multi-language – German and English. When first visited the language will be the same as the browser language. If the user switches the language a cookie is set to store the selected language. But the language is not indicated in the URL (e.g. /en
or /de
), it’s just mydomain.com
in both cases. What I do is changing the lang
attribute in the html
tag in lang="de"
or lang="en"
. I thought that would be friendly enough for Google.
My question is how to implement the hreflang
correctly. All the example I find deal with different language folders like mydomain.com/en/
, subdomains en.mydomain.com
or extensions mydomain.com/?lang=en
.
Should I switch the hreflang
tag dynamically via JS depending on the selected language, so when the user sees the English version the hreflang
would be de-DE
because there’s the same content also in German:
<link rel="alternate" href="http://example.com" hreflang="de-DE" />
And when the user sees the Website in German:
<link rel="alternate" href="http://example.com" hreflang="en-EN" />
But that’s seems odd because the href
value would be the same in both cases …