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?
After reading a number of sources, it seems best to skip if only 1 language, or display for all languages if more than 1.
So, proposing this: https://github.com/zencart/zencart/pull/1314
Hi,
I have implemented the mod proposed so the html_header section becomes
But I get a blank page and the following error logPHP Code:
// BOF hreflang for multilingual sites
if (isset($language_list) || $language_list = $lng->get_available_languages() && sizeof($language_list) > 1) {
foreach($language_list as $key=>$value) {
echo ' <link rel="alternate" href="' . ($this_is_home_page ? zen_href_link(FILENAME_DEFAULT, 'language=' . $value['code'], $request_type) : $canonicalLink . (strpos($canonicalLink, '?') ? '&' : '?') . 'language=' . $value['code']) . '" hreflang="' . $value['code'] . '" />' . "\n";
}
}
// EOF hreflang for multilingual sites
PHP Fatal error: Call to a member function get_available_languages() on a non-object in /home2/xxxxx/public_html/includes/templates/responsive_classic/common/html_header.php on line 71
I have noticed that in github the file lines to modified start with 48 while in my file the lines wereis starts at 73.PHP Code:
// BOF hreflang for multilingual sites
I would like to understand this.
Thanks.
Happy New Year from Italy
enzo
That's because the change posted is for v1.6.0.
For your v1.5 site, do what torvista posted above to get it to output the tags for all languages. And since you're supporting multiple languages already you won't need the other part of the change I mentioned in v160.
Is the code in html_header already corrected in 1.55e (I copied the code from zen-cart 1.55e) or should I still apply the fix described in this forum ( I have 3 languages installed)?