Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Expand upon the existing hreflang support (#2378127: Support for rel="alternate" hreflang="x") to automatically make a version of the tag available for each available locale.
Comment | File | Size | Author |
---|---|---|---|
#28 | metatag-n2597301-28.patch | 2.18 KB | DamienMcKenna |
#12 | metatag-n2597301-11.patch | 13.96 KB | DamienMcKenna |
#12 | metatag-n2597301-11.interdiff.txt | 669 bytes | DamienMcKenna |
Comments
Comment #2
DamienMcKennaOnce this is added we'll also add the x-default tag: #1969400: Add the hreflang="x-default" meta tag
Comment #3
DamienMcKennaOh, the other issue didn't actually *add* support, it just said "use this module instead." Doh.
Comment #4
DamienMcKennaThis should cover it. It adds the hreflang="x-default" meta tag and automatically adds hreflang tags for each enabled locale. It also, by default, removes any hreflang="LANGCODE" tags that match the x-default value, per Google's recommendation. There's a test file but it needs to be done later.
Comment #5
DamienMcKennaThis is what it looks like:
Comment #6
DamienMcKennaClosed a duplicate: #1969400: Add the hreflang="x-default" meta tag
Comment #7
DamienMcKennaGoing to be finishing this in time for the next release, just need to finish the i18n functionality first and then write some tests.
Comment #8
DamienMcKennaFYI I wrote a patch to add a token to the Entity Translation module that works really well with this: #2603056: Provide tokens for URLs of all available translations for a given entity
Comment #9
DamienMcKennaThis merges in the token from the other issue, sets up defaults based upon the token, and improves the help text.
Comment #10
DamienMcKennaA minor mistake.
Comment #12
DamienMcKennaA minor wording fix.
Comment #13
DamienMcKennaCommitted.
Comment #15
Perignon CreditAttribution: Perignon commentedDeja vu. I just started looking for something to provide the hreflang tag today and was hoping metatag did before I threw the code into an existing custom module on my site.
Comment #16
Perignon CreditAttribution: Perignon commentedWhat could cause this to not work? Something obviouse I am hoping.
I been testing this yesterday and this morning and I am not getting the metatags in the HEAD of the document of nodes.
I turn dupes on as well.
Comment #17
Perignon CreditAttribution: Perignon commentedThis is my settings for my node. Since I do not have translations I only set the default to the source.
Comment #18
Perignon CreditAttribution: Perignon commentedSo I installed on a default Drupal 7 and it works. Therefore it is something in my code base not allowing it to work. If you can throw me any ideas that would be much appreciated. Once I figure out they conflict we can document it if it is something someone else may run into.
Comment #19
DamienMcKennaIf you don't have translations installed then [node:source:url] won't have a value, it depends upon the $node->tnid value.
Comment #20
Perignon CreditAttribution: Perignon commentedThat is rather interesting. You are right that I have the "Content Translation" module shut off. Why did it not throw an error that the tocketn [node:source:url] was not available?
Comment #21
Perignon CreditAttribution: Perignon commentedSo the problem was the token being empty.
Is this worth documenting? I've also just found that even with the content translation module enabled that the token [node:source-url] is still empty. So for those of us just trying to get the default hreflang tag and have no other translations, you just need to use the node/page URL.
Comment #22
DamienMcKennaYes, it's worth documenting, and the default token stuff should probably check to make sure the module is enabled.
Comment #23
Perignon CreditAttribution: Perignon commentedYeah.... We got more issues. I would suggest that the default values be empty. After installing the module on my production site I found I could not publish any nodes. All threw errors saying that [node:url-en] did not exist. And what I found was the default value got put into every configuration causing everything to have a token that doesn't exist. I've had to go through all of my metatag settings and overrides and remove the language-specific value.
Installing this module on a site without localization will "freeze" all publishing of the site till you correct the default values.
So I would recommend this get removed or changed so that it tests for the existence of the language specific token first:
Comment #24
Perignon CreditAttribution: Perignon commentedOddly enough, even though I had not overrode the Node metatag configuration it had the wrong token in it after setting global configuration to what I need. Maybe just a fluke.
Comment #25
DamienMcKennaThat's strange, because the tokens are added by the module itself.
Comment #26
Perignon CreditAttribution: Perignon commentedThe [node:url-LANG]?
Comment #27
DamienMcKennaYep :)
Comment #28
DamienMcKennaHow about this?
Comment #30
DamienMcKennaCommitted.
Comment #31
LiamPower CreditAttribution: LiamPower at Reading Room commentedWhen testing this I found that it's not picking up the translated nodes within metatag_hreflang_tokens as the $node->translations wasn't displaying the translations found in the node translate tab.
I found that getting the translations using translation_node_get_translations($node->nid) returned my correct translations.
The below is what worked for my translations.
Comment #32
DamienMcKennaWere you using the core "Content translation" module or Entity Translation?
Comment #33
LiamPower CreditAttribution: LiamPower at Reading Room commentedI didn't originally set this website up and it has both of the modules enabled but I believe the node was translated with 'Content Translation'
Within the publishing options Multilingual support the option: 'Enabled, with translation' is selected.
Comment #34
DamienMcKennaLets move this into a new ticket: #2627598: Custom tokens for hreflang not working