On a Joomla website with multilanguage setup ( https://docs.joomla.org/J3.x:Setup_a_Multilingual_Site ), activate the "Add alternate meta tags" setting of the Language Filter plugin.
This means that on the pages available in different languages on the frontend, the plugin will add an alternate link meta tag for each language.
However, it also adds the link tag for the current language. This is not necessary (actually I think it shouldn't be the case https://moz.com/learn/seo/hreflang-tag ) and due to the way the Document class is written, it backfires in some cases.
For example, if an extension adds a canonical link tag to the header for the current page (it is best practice as far as I know : https://www.lumar.io/blog/best-practice/canonical-tags-easy-dos-donts/#:~:text=All%20pages%20(including%20the%20canonical,to%20prevent%20any%20possible%20duplication. ) before the Language Filter plugin runs in onAfterDispatch, the Language Filter plugin will overwrite the canonical link tag to a hreflang tag for the current language.
On the page of the relative URL collection/lady-datejust/lady-datejust-279138rbr-0015 which uses the en-US language, I want to have:
<link href="https://xxx.com/collection/lady-datejust/lady-datejust-279138rbr-0015" rel="canonical">
<link href="https://xxx.com/fr/rolex/collection/lady-datejust/lady-datejust-279138rbr-0015" rel="alternate" hreflang="fr-FR">
<link href="https://xxx.com/collection/lady-datejust/lady-datejust-279138rbr-0015" rel="alternate" hreflang="en-US">
<link href="https://xxx.com/fr/rolex/collection/lady-datejust/lady-datejust-279138rbr-0015" rel="alternate" hreflang="fr-FR">
I tested it on Joomla 4 and Joomla 5rc2 with the latest version of HikaShop but I think it would be the same on a Joomla article page available in different languages with an extension adding a canonical tag to it before the onAfterDispatch event.
This is an issue that was reported on our forum:
https://www.hikashop.com/forum/product-category-display/907095-issue-ith-canonical-urls.html
I think it can be fixed by changing the line:
$language->link = Route::_($currentInternalUrl);
to:
unset($languages[$i]);
in the Language Filter plugin's onAfterDispatch function in order to skip the current language.
Labels |
Added:
No Code Attached Yet
|
Main issue here is that when "Add alternate meta tags" is on yes, it makes the canonical tag disappear
Main issue here is that when "Add alternate meta tags" is on yes, it makes the canonical tag disappear
as it should
So it's expected to not have the alternate href of the other language when you have the canonical URL tag?
On another site, both the canonical tag and the href tags are there. I'm lost
The canonical tag in joomla refers to a canonical domain not a canonical url
rel=alternate is like saying that the url is a soft canonical url for that language
Easier if I explain with an example.
I'm supposed to have in my source code:
<link href="https://xxx.com/collection/lady-datejust/lady-datejust-279138rbr-0015" rel="canonical">
<link href="https://xxx.com/collection/lady-datejust/lady-datejust-279138rbr-0015" rel="alternate" hreflang="en-US">
<link href="https://xxx.com/fr/rolex/collection/lady-datejust/lady-datejust-279138rbr-0015" rel="alternate" hreflang="fr-FR">
But I have this:
<link href="https://xxx.com/collection/lady-datejust/lady-datejust-279138rbr-0015" rel="alternate" hreflang="en-US">
<link href="https://xxx.com/fr/rolex/collection/lady-datejust/lady-datejust-279138rbr-0015" rel="alternate" hreflang="fr-FR">
After doing some tests, I noticed that if I disable Add Alternate meta tags, the canonical link is back (but of course it's not a solution).
However, it also adds the link tag for the current language.
I agree that seems to be wrong/bugCorrection after looking at the spec it has to exist on all the languages see https://developers.google.com/search/docs/specialty/international/localized-versions#common-mistakes
Note that what is written there is not the same. What it says is that if [page EN] has a hreflang tag to [page FR], then [page FR] has to have a hreflang tag to [page EN]. I completely agree with this.
The problem pointed at here is that [page EN] has a hreflang tag to [page EN] (itself), which also has the side effect of removing the canonical tag.
I think I found the solution to this issue. The line:
if($i !== $this->current_lang)
needs to be added before the line:
$doc->addHeadLink($server . $language->link, 'alternate', 'rel', ['hreflang' => $i]);
in the file plugins/system/languagefilter/src/Extension/LanguageFilter.php
That way, the language filter plugin will skip adding the hreflang tag for the current language and only add it for other languages.
and that would be wrong as stated before at the link I shared from google
If page X links to page Y, page Y must link back to page X.
Or have I misunderstood that statement?
I agree with that statement. But we're not talking about this here.
The problem I'm talking about is that at the moment page x is linking to both page x and page y, and that page y is linking to both page x and page y.
My proposed change make it so that page x only links to page y, and that page y only links to page x.
I hope it is more clear.
Note that we found the solution to this problem:
https://www.hikashop.com/forum/product-category-display/907095-issue-ith-canonical-urls.html#356157
It's been tested for several weeks and after this change, everything works as expected.
Labels |
Added:
bug
|
I agree that seems to be wrong/bugCorrection after looking at the spec it has to exist on all the languages see https://developers.google.com/search/docs/specialty/international/localized-versions#common-mistakes