Guide
Declared and actual page language
When the declared language of a page and the language of its text do not match: the lang attribute and the hreflang code.
A page states its language in two places: in the lang attribute of the <html> element, for example <html lang="de">, and in its own hreflang tag. The scanner compares both with the language the main text of the page is actually written in.
Google determines the language of a page from its visible content and does not use the lang attribute for this. The two findings in a scan report covered here therefore weigh differently: a wrong lang attribute mainly affects browsers, screen readers and translation tools; a hreflang code that does not match the text usually means that a language version has not been translated.
The scanner only reports these findings when the main text is long enough and the language detection is confident. Short pages, pages with a lot of quoted or technical text, or with several languages on one page can still be misjudged, so look at the page before you change anything.
The lang attribute does not match the text
Finding in the report: HTML_LANG_MISMATCH
What it means
The lang attribute of the page names one language, but the main text is written in another, for example <html lang="en"> on a German page.
This is an inconsistency rather than a ranking problem: Google does not use the attribute to determine the language. Screen readers, however, use it to choose the pronunciation, browsers to offer a translation, and translation tools to recognize the source language.
The finding in the scan report names the declared value, the detected language and how confident the detection was.
Typical causes
- The theme writes the
langattribute with a fixed value instead of taking it from the CMS, so every language version shows the same language. - The language of the website or of the language version is set incorrectly in the CMS.
- The page has not been translated yet, although its language version already exists. Then the
langattribute is right and the text is not.
How to check
- Open the page source and look at the
<html>element at the very top. - Read the main text of the page: which language is it really written in?
- If the text is in the right language, the
langattribute is wrong. If thelangattribute is right, the text has not been translated.
How to fix
- Set the
langattribute to the language of the text. In a CMS, check the language settings of the website or of the language version, and the theme's template for the<html>element. - If the text has not been translated, translate it, or do not publish the language version yet.
<html lang="de">
How to confirm the fix
- Check the
<html>element in the page source. - Scan again: the finding disappears from the report once the attribute and the text match.
Content is not in the declared language
Finding in the report: CONTENT_LANGUAGE_MISMATCH
What it means
The page is offered in the set of hreflang tags under one language code, but its main text is in another language. For example, it is declared as the Spanish version, but its text is English.
Search engines may then show this page to people searching in the declared language, who find a text in another language. Google warns that translating only the navigation and other recurring parts while the main content stays in one language makes for a bad user experience.
The finding in the scan report names the declared language code, the detected language and how confident the detection was.
Typical causes
- The translation has not been done or published yet, and the page shows the original text.
- Only the menu and the page frame are translated, not the main text.
- The page is assigned to the wrong language in the CMS, so its hreflang code is wrong.
How to check
- Open the page and read its main text.
- Check in the CMS which language the page is assigned to, and whether a translation exists and is published.
How to fix
- Translate the main text and publish the translation.
- If the page is assigned to the wrong language, correct the assignment in the CMS; the translation plugin then writes the right hreflang code.
- Until the translation is ready, do not publish the language version, so that it does not appear in the set of hreflang tags.
How to confirm the fix
- Read the page again: the main text should be in the declared language.
- Scan again: the finding disappears from the report once the text is in the declared language.
Setup in WordPress & co.
WordPress
WordPress writes the lang attribute from the language of the website (get_bloginfo('language')); themes output it in the <html> element with the function language_attributes(). If a theme writes the attribute itself with a fixed value instead, the language settings of WordPress and of translation plugins have no effect on it.
Sources: WordPress: get_language_attributes() (external link)
A website with its own code, or a simple site without a database
Set the lang attribute of each language version from the same data as its hreflang code, for example <html lang="de"> on the German pages.
If a page contains a passage in another language, mark only that passage, for example <blockquote lang="en">, and keep the language of the page on the <html> element.