#922 Posted in ‘Route 66’

Latest post by Lefteris Kavadas on Friday, 23 September 2022 12:21 EEST

Henrietta Lorko
We're having trouble setting the hreflang. The following is currently displayed for our website.
Example French start page:

<link href="https://www.example.de/en/" rel="alternate" hreflang="en">
<link href="https://www.example.de/de/" rel="alternate" hreflang="de">
<link href="https://www.example.de/es/" rel="alternate" hreflang="es">
<link href="https://www.example.de/it/" rel="alternate" hreflang="it">
<link href="https://www.example.de/fr/" rel="canonical">


Our SEO agency says the correct hreflang must be:
<link href="https://www.example.de/en/" rel="alternate" hreflang="en">
<link href="https://www.example.de/de/" rel="alternate" hreflang="de">
<link href="https://www.example.de/es/" rel="alternate" hreflang="es">
<link href="https://www.example.de/it/" rel="alternate" hreflang="it">
<link href="https://www.example.de/fr/" rel="alternate" hreflang="fr">
<link href="https://www.example.de/fr/" rel="canonical">

Google Reference:
https://developers.google.com/search/docs/advanced/crawling/localized-versions?hl=en "For each variation of the page, include a set of <link> elements in the <head> element, one link for each page variant including itself. The set of links is identical for every version of the page."

=> The "including itself" is missing and our "set of links" is not identical on every page.
Can this be adjusted somewhere?

Lefteris Kavadas
Hi Henrietta,

No Route 66, has no option for this kind of links. This is handled by core Joomla multi-language system.
I also don't think that it makes any point adding the same URL twice as your SEO agency suggests.
One thing you can try is edit the plugin named "System - Language Filter" and enable the option named "Add x-default Meta Tag".
Please let me know if that makes any difference.

Regards

Henrietta Lorko
Hello Lefteris, thanks for your reply.
We had the "Add x-default Meta Tag" option enabled from the start.
Nothing changes there. The agency says you need 2 lines for the default language in the hreflang:

<link href="https://www.example.de/fr/" rel="alternate" hreflang="fr">
and
<link href="https://www.example.de/fr/" rel="canonical">

Whether I enable the option or not, the default language only has one line of code
Did you look at the reference from google?

Regards

Lefteris Kavadas
Hi Henrietta,

Yes I did look at the reference and I found no duplicate links in the examples. That's why I think what your agency suggests is not correct. The current language link is redundant since the canonical link is there.
And that's why we are not going to add this to our extension.
In any case, if you want to do this, you can use the following code:
$language = JFactory::getLanguage();
$languages = JLanguageHelper::getLanguages('lang_code');
$document = JFactory::getDocument();
$document->addHeadLink(htmlspecialchars(JUri::current()), 'alternate', 'rel', ['hreflang' =&gt; $language[$language-&gt;getTag()]->sef]);


You can add this in your template index.php file and it should work with no issues. If not please let me know.

Regards

Henrietta Lorko
Hello, thank you. We put the code in the index.php file of the child theme. Unfortunately we don't see any changes. Is the index.php correct?

Henrietta Lorko
Hi, There seems to be indeed a problem in Joomla Core. The hreflang seems really buggy. A user from the community wrote a plugin for it: https://github.com/TheWhykiki/seolanghref?fbclid=IwAR1uOHo800VzdlxGTeJQg3BWZ_LLtXAIQ5OWnOAvZmWMYnEqN5Or9qUl2HI

Lefteris Kavadas
Thanks for letting me know. I will give it one more try.

Note: An active subscription is required in order to get support for our paid extensions. For our free extensions, if you don't have an account, register and then submit your support request.  In case you just want to ask a question, you can also use the contact form .

Firecoders
Are you using our extensions? Please post a review at the Joomla extensions directory!
Post a review