Add hreflang to the HTML head on all pages

Created on 24 June 2015, over 9 years ago
Updated 26 January 2023, almost 2 years ago

Bug from https://www.drupal.org/node/2303525 β†’

As described in the description of the ticket as well as in the description of the page that is linked off to in the ticket that google (https://support.google.com/webmasters/answer/189077) has written up this tag needs to be in the head of the page.

The implementation that currently sits in core only adds these tags to the language switcher and not into the head of the html page.

Updates on reproducing issue as mentioned by #3. 2020/06/17

Once the language and content translation modules are enabled and configured, all entities (term, contents) created will have hreflang tag in head of html whether it is translated or not. Yet the default homepage (/node) doesn't apply.

There is an improvement issue filed for Improve the alternate hreflang implementation
https://www.drupal.org/project/drupal/issues/2994800 β†’ .

steps to reproduce

1. install Drupal 9.1.dev with default language
(no hreflang tag in head of default homepage)

2. create new entity node of any content type (e.g. articles, /node/1)
(no hreflang tag in head of entity)

3. enable module language and content_translation, activate new language in /admin/config/regional/language and allow content types translation in /admin/config/regional/content-language.

4. Translate node/1 to chosen language.
(hreflang tag appears on both entity head, e.g. /node/1 & /zh-hant/node/1)

5. If default front page is set as "/node", expect no hreflang tag shown in head unless set default frontpage to other entity pages like "/node/1".

Default frontpage & HTML

Entity pages & HTML


πŸ“Œ Task
Status

Active

Version

10.1 ✨

Component
Language systemΒ  β†’

Last updated about 7 hours ago

  • Maintained by
  • πŸ‡©πŸ‡ͺGermany @sun
Created by

πŸ‡¨πŸ‡±Chile lathan Chile

Live updates comments and jobs are added and updated live.
  • D8MI

    (Drupal 8 Multilingual Initiative) is the tag used by the multilingual initiative to mark core issues (and some contributed module issues). For versions other than Drupal 8, use the i18n (Internationalization) tag on issues which involve or affect multilingual / multinational support. That is preferred over Translation.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs accessibility review

    Used to alert the accessibility topic maintainer(s) that an issue significantly affects (or has the potential to affect) the accessibility of Drupal, and their signoff is needed (see the governance policy draft for more information). Useful links: Drupal's accessibility standards, the Drupal Core accessibility gate.

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    Tagging for issue summary update with what the proposed solution should be.
    As noted in #18

    It's not clear to me why the hreflang link tags should only be generated for translated entities. Other pages, such as views, and untranslated content with a translated user interface, need them too.

    So what is the desired behavior here?

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Also meant to tag for accessibility if they can offer guidance

  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

    I'm not sure as I didn't file this issue, but I think it's a feature request for core to generate hreflang tags on pages that are not translated entities. Or it could also be thought of as a bug report on the existing feature, where core generates hreflang tags only for translated entity pages.

    On a typical multilingual site, other kinds of pages (e.g. the default front page, /node, which is a view page) can be accessed in different languages - which would show some mix of translated user interface and/or translated content - and for SEO purposes you'd want to have hreflang tags on these pages.

    At the moment this feature is provided by contrib Hreflang module β†’ , which has ~12,500 installs on drupal 7 thru 10, so seems potentially useful enough to be part of core, but *shrug* could also be won't fixed if core is not interested.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Seems like it wouldn’t be terrible to fold that in but don’t know the process for that

  • πŸ‡ΊπŸ‡ΈUnited States mfb San Francisco

    Adding πŸ› Hreflang on non-canonical content pages Needs work as a related issue as it has to do with hreflang. (Tl;dr: There's an assumption that hreflang and other meta tags can be built up in the #attached array where they will be automatically de-duplicated and other modules can alter them. But in fact, the hreflang tags should change depending on the query arguments on the page, and so I think they should be using a placeholder that gets swapped out at the last minute via a lazy builder. Although this change would be a BC break.)

  • Status changed to Active almost 2 years ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    But in fact, the hreflang tags should change depending on the query arguments on the page, and so I think they should be using a placeholder that gets swapped out at the last minute via a lazy builder. Although this change would be a BC break.)

    If it's just changing something in a render array, that's fine with a change record / release notes mention in a minor release.

    I can't see a patch here, so switching the status to 'active', this seems reasonable to add but I don't think it's a bug as such (and the contrib module can be used in the meantime), so moving to 'task'.

Production build 0.71.5 2024