Closed (fixed)
Project:
Hreflang
Version:
7.x-1.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
17 Nov 2014 at 07:32 UTC
Updated:
12 Dec 2021 at 20:19 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
2phaAs I said, I'm not sure about the x-default as it seems hard to get good information.
But here is a patch that sets x-default for the default language.
Comment #3
damienmckennaThis should work.
Comment #5
damienmckennaRerolled.
Comment #6
joelpittet@DamienMcKenna should this be an option instead of forced in there?
And should it be additional to the normal hreflang? or should it override the language code of the default like you have it?
Comment #7
2phaI could not find any real specific information on if you would have both default and en for a site that was default english, but from what I read it suggested that default would be enough.
Comment #8
joelpittetYeah me neither, I did have some negative results testing it with this tool though when I had both, so maybe this is the right way, just curious...
http://flang.dejanseo.com.au/
Comment #9
mfbThis doesn't make any sense to me; this will make an x-default hreflang tag for any pages in the site's default language. But you would only want to use x-default for a language-neutral front page that just has a language switcher or language map.
Not sure this module needs to support this as it's probably uncommon, and such a site could use hook_html_head_alter() in its custom code to setup the x-default tag on the front page
Comment #10
damienmckennaI'm starting to wonder if this variation of the meta tag should be handled by the Metatag module instead, so it could be handled per entity. Thoughts?
Comment #11
2pha@mfb.
I thought it was meant to be on every page so that google would know that "mysite.com/mynode" and "mysite.com/es/mynode" are the same node for different languages. That how I understand it.
@DamienMcKenna
I think the metatag module is probably the way to go.
Comment #12
joelpittet@see https://support.google.com/webmasters/answer/189077?hl=en
Comment #13
mfb@2pha the link you put up in the issue description is pretty clear that x-default is for international landing pages, or pages that dynamically alter their content for the user.
This module doesn't automagically know that a page is an international landing page or that it dynamically alters its content - and that seems like a difficult thing for it to know given the variety of ways a Drupal site could render content. I'd say it's up to a site developer to setup the correct link tags in these cases, but I'm open to patches if someone has an idea for something useful here.
Until then this module is handling only the use case of a site with a default language, and other languages available in a language switcher (I think of the link tags as a machine-readable language switcher).
Comment #14
2pha@mfb
Maybe that link was not the best one, the one linked to by joelpittet is better and as he quoted it does seem like x-default is only for "international landing pages, or pages that dynamically alter their content for the user".
The example on the bottom of that page suggests to me that x-default should be used on all pages, even though in the example the use the homepage. Maybe my interpretation of "international landing page" or "pages that dynamically alter their content" is different.
"Until then this module is handling only the use case of a site with a default language, and other languages available in a language switcher (I think of the link tags as a machine-readable language switcher)."
This is exactly my use case, but I have interpreted the documentation for x-default that you should have it on every page and it should point to the url of the page in the default language (which should be the same as the canonical).
After looking into it again I am still seeing conflicting views in blog posts and comments on the use of x-default, so I though I would check how google is doing it for their sites. Checking the google store site, it seems that they set x-default on all pages.
Here is the hreflang section from the page of a game on the google store. You can see that the include an x-default, but also a specific english hreflang (I am assuming at this point that the default page is in english). This suggests to me that x-default should be on every page, but not override the default language specific hreflang
Does all this make sense? At this point it is doing my head in and I am not even sure if we are talking about the same thing. It late here, I'm going to bed :)
Comment #15
mfbThe reason google has an x-default tag for https://play.google.com/store is because this page dynamically alters the language for the user by geolocating the user's IP address. If you load https://play.google.com/store from Germany, it will be in German; if you load https://play.google.com/store from the US, it will be in English. You can easily test this by accessing it with Tor Browser. (If you are logged in to Google, then it should default to your user account's language, rather than using your geolocated IP address.)
Comment #16
2phaAhh, yes, I see now that by dynamic they mean changing the content via a url parameter or something else, rather than a different url.
Comment #17
2phaI have noticed now that when you turn off "Determine the language from the URL (Path prefix or domain)." and turn on " Determine the language from a request/session parameter." so it uses a url parameter to set the language (?language=en by default), then you get unexpected results for the hreflag meta tags.
When using request/session parameter, I only get 1 hreflang meta tag which is wrong.
Maybe I should start a new issue for this?
Comment #18
mfbok this module wasn't working with session detection, but I just fixed it and added a test, so we don't need a new issue. I'd say an x-default tag does make sense for session detection, basically each page could specify the URL without language parameter as x-default, and then we would also need to add the missing language parameter to the default language's hreflang tag.
Comment #19
2phaI just tried latest dev and it does indeed work for session detection.
This confuses me:
"and then we would also need to add the missing language parameter to the default language's hreflang tag".
Isn't that the point of x-default? that any missing would default to the x-default?
Comment #20
mfbCurrently, if the default language is "en", at http://www.example.com/ there is an hreflang tag with hreflang="en" and the URL is missing the language parameter. Meanwhile at http://www.example.com/?language=fr there is an hreflang tag with hreflang="en" and the URL has "?language=en". Seems like this inconsistency should ideally be fixed.
Comment #22
mfbThis issue still needs work as per previous comments
Comment #23
j-leeI have modified the patch from #5 because we need x-default and all languages as link.
drupal_add_html_head_link overrides existing links so i used drupal_add_html_head directly.
Because this was a quick and dirty patch, I think there is a better solution for this.
Comment #24
damienmckennaTriggering the testbot on the patch in #23.
Comment #26
j-leeAfter monitor a page and further investigations, x-default must return the frontpage url if it is a language neutral frontpage.
E.g. http://www.mypage.com/ shows english content or german content, depending on the language negotiation.
The patch implements this, but does not check if the page has a language neutral frontpage.
Comment #27
j-leeLeading the x-default to the front page is definitely wrong.
Fixing patch from #23.
Comment #29
j-leeComment #30
rolfmeijer commentedThe patch from #29 applied to 7.x-1.2 and works as expected. It also works in combination with domain and domain_locale, it gets the default language of the current domain. Nice.
Comment #32
alphex commentedCan confirm, #29 works for me as well.
Comment #33
giupenni commented#29 works for me as well.
Comment #34
j-leeThis patch should work with the test.
Comment #36
rcodinaI update the patch so it applies with latest dev version.
Comment #37
rcodina@mfb Could you please test this patch? Thanks!
Comment #38
gauladell commented#36 works for me
Comment #39
mfbAdding the "needs tests" tag and linking to the related core issue: #2959727: drupal_add_html_head_link() needs to allow multiple hreflang tags to point to one URL.
Comment #40
mfbThe bug in core is fixed now so we should be able to use drupal_add_html_head_link()
Comment #41
mfbI added an opt-in setting for the
hreflang="x-default"tag (so we don't break things for sites that weren't expecting changes to their hreflang tags) and a test for the new functionality.Comment #42
mfbComment #43
mfbJust realized this module hasn't been specifying $header = TRUE when calling drupal_add_html_head_link(), so backing out my unintentional change there.
Comment #45
mfb