When Interface Translation module is enabled in Drupal 8, I get hreflang links to ALL languages on the site for every page view sourse, no matter if the content is translated or not.

enter image description here

If alternate hrefland is active on all of the pages, even untranslated ones, it creates some SEO problems.

I want to remove these links. Is any Drupal way to do this?

  • 3
    I'm voting to close this question as off-topic because it refers to a Drupal Core bug that should be addressed in its issue queue at drupal.org: drupal.org/node/2521782 – Mario Steinitz Mar 22 '19 at 5:27

These are added via a hook_page_attachments() implementation in content_translations.module. The code looks like it should not add any hrefs unless an entity translation has been created.

Some tests on my site seem to indicate that this is working correctly. Do you have another module that is trying to add these and doing it incorrectly?

That said, you should be able to implement a hook_page_attachments() function (in something with a execution weight that runs after the content code). In this look at the $page['#attached']['html_head_link'] array for the items to remove.

  • 1
    Yes, I have enabled "Alternate hreflang" module, if I uninstalled this module then these links are removed. Thanks. – latikas Oct 5 '17 at 6:22
  • But if I uninstalled this module, still we are getting hreflang for other languages for inner pages. I tried to use hook_page_attachments_alter() for our requirement but it is not overwriting the existing code. Did not understand how to remove those links. – latikas Oct 6 '17 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.