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
default page settings
default page html

Entity pages & HTML

entity page settings
entity page html

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lathan’s picture

Issue summary: View changes
pdenooijer’s picture

Status: Active » Closed (duplicate)
FileSize
53.08 KB

This is already fixed in the bug report mentioned at the start of the bug report, https://www.drupal.org/node/2303525.

I tested it on the current (25-June-2015) 8.0.x branch of drupal and I can confirm that there is a hreflang tag in the HTML head. See the screenshot for conformation.

lathan’s picture

Status: Closed (duplicate) » Active

Right so i have figured out what the issue is, the front page if it is not a instance of a drupal entity does not get this hreflang tag, this is probably the most beneficial page to have this specific tag as it has quite an impact on SEO.

The second issue is that when a node has been translated into different languages. This current patch assumes that both languages are published, we then start seeing 404's in google crawl report.

Anonymous’s picture

This needs an IS update, and I'm wondering as per #3 whether or not we need to split this up in two separate tickets.

swentel’s picture

#2521782: HTML head has alternate hreflang links to unpublished translations exists for the 404 (or rather 403)

As for the front page, that is a view, which as far as I know not translatable by default, so I'm not sure there's a bug here.

catch’s picture

Priority: Major » Normal
Status: Active » Postponed (maintainer needs more info)

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

g-brodiei’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active
Issue tags: -Needs issue summary update
Parent issue: » #2994800: Improve the alternate hreflang implementation
FileSize
12.25 KB
32.01 KB
12.04 KB
22.28 KB

Updated the issue summary + steps to reproduce.

Add parent issue "improvement in alternate hreflang tag".
https://www.drupal.org/project/drupal/issues/2994800

g-brodiei’s picture

Just found out that as #5 mentioned, it is expected as hreflang tag not displaying on views pages, even if the configurations are translated. On the other hand, translated entities have hreflang tag in head. Which was commited in https://www.drupal.org/project/drupal/issues/2303525.

I guess the issue should be that we need an improvement on addressing hreflang tag on other non-entity based pages like @mfb said.

https://www.drupal.org/project/drupal/issues/2303525#comment-9368051

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.

For another solution, this module adds hreflang link tags to all pages on the site: https://www.drupal.org/project/hreflang

I'll suggest this issue to be closed.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

madhu_h’s picture

Verified and tested.

Testing Steps:
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".

Test Results:
- When we visit entity pages, hreflang tag is appearing in head
https://www.drupal.org/files/issues/2021-10-04/Screenshot%202021-10-04%2...
- However in case of view pages,hreflang tag is not appearing in head
https://www.drupal.org/files/issues/2021-10-04/Screenshot%202021-10-04%2...

Test Status: NEEDS REVIEW

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs issue summary update

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?

smustgrave’s picture

Also meant to tag for accessibility if they can offer guidance

mfb’s picture

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.

smustgrave’s picture

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

mfb’s picture

Adding #3226887: Hreflang on non-canonical content pages 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.)

catch’s picture

Title: (hreflang) tag is not in the HTML head » Add hreflang to the HTML head on all pages
Category: Bug report » Task
Status: Needs work » Active

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'.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.