Does anybody know exactly how to implement the hreflang tags to a multilanguage store? I guess it should be added to html_header.php, but what would the code look like?
I have the CEON URI module installed also.
Printable View
Does anybody know exactly how to implement the hreflang tags to a multilanguage store? I guess it should be added to html_header.php, but what would the code look like?
I have the CEON URI module installed also.
Thanks for the link, however I am familiar with the tags, I was more referring to what the php code would look like.
Hmmmm......
example HTML
Same example using PHPCode:<a href="http://www.w3schools.com" hreflang="en">W3Schools</a>
I have a feeling that that this isn't quite what you are seeking though ???Code:<?php
echo "<a href=\"http://www.w3schools.com\" hreflang=\"en\">W3Schools</a>" ;
?>
Cheers
RodG
It was something like that I was looking for. However the hreflang tag needs to be "assigned" to each zencart page; for multiple languages. I guess it couldn't be made with a few lines of code.
I still don't quite follow what you are trying to do or achieve, but I'm guessing that you want the hreflang=\"en\" to be replaced with a variable?
If so then something like......
......should probably do the trick.Code:<?php
$myVar = "en" ;
echo "<a href=\"http://www.w3schools.com\" hreflang=\".$myVar.\">W3Schools</a>" ;
?>
You will of course need to set the value of $myVar according to whatever condition it is you need it for though.
Perhaps if you could explain or demonstrate exactly what it is you are trying to do I/we may be able to offer more/better help.
Maybe this will also help?
https://support.google.com/webmaster...r/189077?hl=en
Cheers
RodG
Thanks, and sorry for not explaining clearly what it is Im trying to do. Here it is:
I have these two domains:
http://www.tronicore.co.uk/
http://www.tronicore.dk/
on the same server/same zencart installation. I am re-directing each language to the correct domain in htaccess.
The co.uk domain has all product and catagory pages like this example:
http://www.tronicore.co.uk/en/rs232-...422-converters
and all .dk product and catagory pages like this example:
http://www.tronicore.dk/da/rs232-rs485-konvertere
The CEON URL module adds the /en/ and /da/ sub-folders, and also the re-written URL of course.
Now I would like the hreflang tags to be assigned to all product and catagory pages in accordance to the link you mentioned (https://support.google.com/webmaster...r/189077?hl=en)
So for example the URL:
http://www.tronicore.co.uk/en/rs232-...422-converters
should contain:
<link rel="alternate" hreflang="en" href="http://www.tronicore.co.uk/en/rs232-rs485-rs422-converters" />
and the URL:
http://www.tronicore.dk/da/rs232-rs485-konvertere
should contain:
<link rel="alternate" hreflang="da" href="http://www.tronicore.dk/da/rs232-rs485-konvertere" />
All other product and category pages should follow this pattern.
Zen Cart 1.55a
in templates/YOUR_TEMPLATE/common/html_header.php
we have
This produces a hreflang for each of the OTHER languages, but not that of this actual page.Code:<?php
// BOF hreflang for multilingual sites
if (!isset($lng) || (isset($lng) && !is_object($lng))) {
$lng = new language;
}
reset($lng->catalog_languages);
while (list($key, $value) = each($lng->catalog_languages)) {
if ($value['id'] == $_SESSION['languages_id']) continue;
echo '<link rel="alternate" href="' . ($this_is_home_page ? zen_href_link(FILENAME_DEFAULT, 'language=' . $key, $request_type) : $canonicalLink . '&language=' . $key) . '" hreflang="' . $key . '" />' . "\n";
}
// EOF hreflang for multilingual sites
?>
ie if you offer english and spanish on your site, the english page generates:
From what I read here,Quote:
<link rel="alternate" href="https://www.YOURSITE.com/somepage?language=es" hreflang="es">
Concise
https://www.semrush.com/blog/7-commo...w-to-fix-them/
Detailed
https://moz.com/blog/using-the-corre...generator-tool
this is incomplete. There should also be a link to the self-same page:
I looked into this after receiving warning emails from Google Search Console,and this was the reason.Quote:
<link rel="alternate" href="https://www.YOURSITE.com/somepage?language=es" hreflang="es">
<link rel="alternate" href="https://www.YOURSITE.com/somepage?language=en" hreflang="en">
So, this link requires commenting out:
Quote:
<?php
// BOF hreflang for multilingual sites
if (!isset($lng) || (isset($lng) && !is_object($lng))) {
$lng = new language;
}
reset($lng->catalog_languages);
while (list($key, $value) = each($lng->catalog_languages)) {
//if ($value['id'] == $_SESSION['languages_id']) continue;
echo '<link rel="alternate" href="' . ($this_is_home_page ? zen_href_link(FILENAME_DEFAULT, 'language=' . $key, $request_type) : $canonicalLink . '&language=' . $key) . '" hreflang="' . $key . '" />' . "\n";
}
// EOF hreflang for multilingual sites
?>
Question:
You suggested commenting out:... But on a site with only one language, that will cause the <link rel=alternate hreflang=foo> to appear. Is that desirable when there's no other language, and the language is already specified in the <html> tag?Code://if ($value['id'] == $_SESSION['languages_id']) continue;
No. That's me not thinking outside my box.Quote:
Is that desirable when there's no other language, and the language is already specified in the <html> tag?