Google hreflang language confusion: Do I have to add hreflang for the page ITSELF?
Asked Answered
M

3

6

On Google's hreflang documentation, in the 2-language example, it says:

Imagine you have an English language page hosted at http://www.example.com/, with a Spanish alternative at http://es.example.com/. You can indicate to Google that the Spanish URL is the Spanish-language equivalent of the English page in one of three ways:

  • HTML link element in header. In the HTML <head> section of http://www.example.com/, add a link element pointing to the Spanish version of that webpage at http://es.example.com/, like this:

    <link rel="alternate" hreflang="es" href="http://es.example.com/" />
    

But in its 3-language example, it says:

If you have multiple language versions of a URL, each language page must identify all language versions, including itself. For example, if your site provides content in French, English, and Spanish, the Spanish version must include a rel="alternate" hreflang="x" link for itself in addition to links to the French and English versions. Similarly, the English and French versions must each include the same references to the French, English, and Spanish versions.

The above is an example for a 3-language site. My website consists of only 2 languages - the default/main ENGLISH and THAI. Do I have to add the tag for the page itself? Google's documentation is not clear about this point and in its example for 2-language site, it is not mentioned.

For example, this is what I put in http://janwawa.com/en/contact.php

<!-- GOOGLE INTERNATIONAL LANGUAGE TARGETING -->
<link rel="alternate" hreflang="th" href="http://janwawa.com/th/contact.php">
<link rel="alternate" hreflang="x-default" href="http://janwawa.com/en/contact.php">
</head>

Is the above correct? Or should I use:

<!-- GOOGLE INTERNATIONAL LANGUAGE TARGETING -->
<link rel="alternate" hreflang="en" href="http://janwawa.com/en/contact.php">
<link rel="alternate" hreflang="th" href="http://janwawa.com/th/contact.php">
<link rel="alternate" hreflang="x-default" href="http://janwawa.com/en/contact.php">
</head>
Mainmast answered 22/12, 2014 at 7:30 Comment(0)
E
1

If your intention is to show them the English page for Chinese speaking users, you can indeed use your second example:

<!-- GOOGLE INTERNATIONAL LANGUAGE TARGETING -->
<link rel="alternate" hreflang="en" href="http://janwawa.com/en/contact.php">
<link rel="alternate" hreflang="th" href="http://janwawa.com/th/contact.php">
<link rel="alternate" hreflang="x-default" href="http://janwawa.com/en/contact.php">

The new x-default hreflang attribute value signals to Google's algorithms that the page doesn’t target any specific language or locale and is the default page when no other page is better suited - Google

Enormous answered 26/12, 2014 at 4:16 Comment(1)
My website has no Chinese version. So if a Chinese viewer is searching, I would want to show them the URLs of English version. I am sure most Chinese don't read in Thai. So I guess I will use back this second example.Mainmast
I
2

Although I agree with Unor that it is not clear why Google recommend to use a self-referencing alternate link, Google's advice (2017) is a clear statement:

If you have multiple language versions of a URL, each language page should identify different language versions, including itself.

For languages or locales not specified by alternate links Google says:

For the default page that doesn’t target any specific language or locale, add rel="alternate" hreflang="x-default".

So, I would use another URL here.

Additionally, I would also recommended to add a canonical link to each page.

Examples

Your English page could look like this:

<link rel="canonical" hreflang="en" href="http://janwawa.com/en/contact.php">
<!-- Alternate links are the same for all pages  -->
<link rel="alternate" hreflang="en" href="http://janwawa.com/en/contact.php">
<link rel="alternate" hreflang="th" href="http://janwawa.com/th/contact.php">
<link rel="alternate" hreflang="x-default" href="http://janwawa.com/default/contact.php">

Your Thai page could look like this:

<link rel="canonical" hreflang="th" href="http://janwawa.com/th/contact.php">
<!-- Alternate links are the same for all pages  -->
<link rel="alternate" hreflang="en" href="http://janwawa.com/en/contact.php">
<link rel="alternate" hreflang="th" href="http://janwawa.com/th/contact.php">
<link rel="alternate" hreflang="x-default" href="http://janwawa.com/default/contact.php">
Institution answered 23/11, 2017 at 10:0 Comment(0)
W
1

Their documentation page is somewhat lousy because they always refer to hreflang="x" where x is just a placeholder for a language tag. The language tag x on its own is not valid, as it has to be followed by a hyphen and an alphanumeric string (x-foo):

privateuse    = "x" 1*("-" (1*8alphanum))

So "[…] the Spanish version must include a rel="alternate" hreflang="x" link for itself […]" doesn’t make sense.

x-default is such a (valid) private language tag, and if you want to follow Google’s interpretation of it, x-default should only be used for language-independent pages that serve as language selectors/redirectors.

So neither of your examples is correct.

You should either

  • include only the link to the translation:

    <!-- on the English page <http://janwawa.com/en/contact.php> -->
    <link rel="alternate" hreflang="th" href="http://janwawa.com/th/contact.php">
    
  • or include both, the link to the translation and the self-referencing link:

    <!-- on the English page <http://janwawa.com/en/contact.php> -->
    <link rel="alternate" hreflang="en" href="http://janwawa.com/en/contact.php">
    <link rel="alternate" hreflang="th" href="http://janwawa.com/th/contact.php">
    

It is beyond me why Google would recommend to have a self-referencing alternate link in the first place, and assuming that it makes any sense, why they don’t recommend this self-referencing link in case of only two languages.

HTML5 defines that the alternate link type references "an alternate representation of the current document". So, using alternate for a link to the current document doesn’t make sense, because it’s not an "alternate representation of the current document", it is the current document.

Wolbrom answered 24/12, 2014 at 12:15 Comment(5)
Although I don't quite understand the use of x-default, I decided to use the second example and remove all <link rel="alternate" hreflang="x-default" href="janwawa.com/en/xxxxx.php"> Thanks for your direction.Mainmast
@LawrenceL.: You could use x-default for example for linking to http://janwawa.com/: a page that a) is not specific to one language, and b) serves as a language selector page.Wolbrom
I am getting more confused. This is what I want to do actually: If the viewer's language is neither English or Thai (in this example the viewer's language is Chinese), I want the viewer to go to the English page. Meaning, English viewers go to English page. Thai viewers go to Thai page. Chinese or any other Non-English/Non-Thai viewers go to English page. So isn't my tags should be: <link rel="alternate" hreflang="x-default" href="janwawa.com/en/mypage.php">Mainmast
Shouldn't I be using the second example (3 lines of tags) in my original question?Mainmast
@LawrenceL.: This markup has nothing to do with automatically redirecting users. It just tells: this is translation of this document in this language. How you decide to redirect users is up to you. When Chinese users visit the Thai version, it’s generally a bad idea to automatically redirect them to the English version (as they would have no chance to see the Thai version if they decide to). So you just offer a language switcher. Now, for your front page, you can use x-default as this page is not language-specific, right? So on this page, you could redirect freely, if you want to.Wolbrom
E
1

If your intention is to show them the English page for Chinese speaking users, you can indeed use your second example:

<!-- GOOGLE INTERNATIONAL LANGUAGE TARGETING -->
<link rel="alternate" hreflang="en" href="http://janwawa.com/en/contact.php">
<link rel="alternate" hreflang="th" href="http://janwawa.com/th/contact.php">
<link rel="alternate" hreflang="x-default" href="http://janwawa.com/en/contact.php">

The new x-default hreflang attribute value signals to Google's algorithms that the page doesn’t target any specific language or locale and is the default page when no other page is better suited - Google

Enormous answered 26/12, 2014 at 4:16 Comment(1)
My website has no Chinese version. So if a Chinese viewer is searching, I would want to show them the URLs of English version. I am sure most Chinese don't read in Thai. So I guess I will use back this second example.Mainmast

© 2022 - 2024 — McMap. All rights reserved.