Option to generate a full set of hreflang tags for nodes with language "Not specified"

Created on 17 September 2019, almost 6 years ago
Updated 9 July 2025, 26 days ago

We often publish content (web pages, documents, videos, etc) in English that is never translated. We want this content to be available on our non-English websites, so we want to set the language to "Not specified" in Drupal 8.

Nodes with language "Not specified" will be available across all of our language sites with a common URL path that only differs by the language prefix.

On our current Drupal 6 site, we generate a full set of hreflang entries for similar content (called "language neutral" in Drupal 6). Here is what that looks like:

<url>
 <loc>https://www.example.com/example-page</loc>
 <lastmod>2018-05-18T15:39Z</lastmod>
 <changefreq>yearly</changefreq>
 <priority>0.8</priority>
 <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/example-page"/>
 <xhtml:link rel="alternate" hreflang="en-GB" href="https://www.example.com/en-gb/example-page"/>
 <xhtml:link rel="alternate" hreflang="de" href="https://www.example.com/de/example-page"/>
 <xhtml:link rel="alternate" hreflang="fr" href="https://www.example.com/fr/example-page"/>
 <xhtml:link rel="alternate" hreflang="es-ES" href="https://www.example.com/es-es/example-page"/>
 <xhtml:link rel="alternate" hreflang="en-AU" href="https://www.example.com/en-au/example-page"/>
 <xhtml:link rel="alternate" hreflang="pt" href="https://www.example.com/pt/example-page"/>
 <xhtml:link rel="alternate" hreflang="en-IN" href="https://www.example.com/en-in/example-page"/>
 <xhtml:link rel="alternate" hreflang="zh" href="https://www.example.com/zh/example-page"/>
 <xhtml:link rel="alternate" hreflang="ja" href="https://www.example.com/ja/example-page"/>
 <xhtml:link rel="alternate" hreflang="es" href="https://www.example.com/es/example-page"/>
 <xhtml:link rel="alternate" hreflang="ko" href="https://www.example.com/ko/example-page"/>
 <xhtml:link rel="alternate" hreflang="ru" href="https://www.example.com/ru/example-page"/>
</url>

This is not happening on the Drupal 8 site. Instead, we see only a single hreflang tag for the default language in the sitemap:

<url>
 <loc>https://dev.flukecal.com/example-page</loc>
 <xhtml:link rel="alternate" hreflang="en" href="https://www.example.com/example-page"/>
 <lastmod>2019-06-04T10:59:51-07:00</lastmod>
 <priority>0.5</priority>
</url>

The question of the correct behavior appears to be settled in this hreflang article by Google:

[https://support.google.com/webmasters/answer/189077]

Some example scenarios where indicating alternate pages is recommended:

  • If you keep the main content in a single language and translate only the template, such as the navigation and footer. Pages that feature user-generated content, like forums, typically do this.
  • If your content has small regional variations with similar content, in a single language. For example, you might have English-language content targeted to the US, GB, and Ireland.
  • If your site content is fully translated into multiple languages. For example, you have both German and English versions of each page.

When we use language "Not specified" as I described above, we create a page in which we "keep the main content in a single language and translate only the template". This is a case in which the Google article recommends indicating alternate pages with hreflang.

I imagine most users use language "Not specified" in a way that is similar to our use case. For the sake of those who don't, maybe we can add an option on the Simple XML Sitemap Settings page to control this behavior.

Maybe a checkbox that says "Generate links for all languages when entity language is not specified"?

✨ Feature request
Status

Needs work

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States markdatter

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Reroll patch from #9 for current state of 4.x and 4.2.2

    Mark as Needs work as I agree with

    If we want to add this to this module, we probably should make it configurable since this is a BC break.

Production build 0.71.5 2024