Add hreflang support to ISC

NOT RECOMMENDED due to the ? character in URL (?setCurrencyId=x) which is not good for Canonical Links

Background

If you have multiple versions of a page for different languages or regions, tell Google about these different variations. Doing so will help Google Search point users to the most appropriate version of your page by language or region.

First of all, if you have a version of a page that you have optimized for the users’ language and location, you want them to land on that page. Having the right language and location dependent information improves their user experience and thus leads to fewer people bouncing back to the search results. Fewer people bouncing back to the search results leads to higher rankings.

The second reason is that hreflang prevents the problem of duplicate content. If you have the same content in English on different URLs aimed at the UK, the US, and Australia, the difference on these pages might be as small as a change in prices and currency. Without hreflang, Google might not understand what you’re trying to do and see it as duplicate content. With hreflang, you make it very clear to the search engine that it’s (almost) the same content, just optimized for different people.

We are using multiple currency display function, so we want to add ‘hreflang‘ tags to all product pages and canonical links should include the current selected currency

Implementation

In /includes/classes/class.product.php

Find

$GLOBALS['ISC_CLASS_TEMPLATE']->SetCanonicalLink(ProdLink($this->_prodname));

Replace

// MOD
//$GLOBALS['ISC_CLASS_TEMPLATE']->SetCanonicalLink(ProdLink($this->_prodname));

if($GLOBALS['CurrentCurrency'] > 1){
	$GLOBALS['ISC_CLASS_TEMPLATE']->SetCanonicalLink(ProdLink($this->_prodname)."?setCurrencyId=".$GLOBALS['CurrentCurrency']);
}else{
	$GLOBALS['ISC_CLASS_TEMPLATE']->SetCanonicalLink(ProdLink($this->_prodname));
}
// MOD

Find

ISC_PRODUCT_VIEWS::logView($this->_prodid);

Replace

(Adjust setCurrencyId=x based on the actual currency setting)

// MOD 
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."\" hreflang=\"x-default\">";
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."\" hreflang=\"en\">";
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."\" hreflang=\"en-us\">";
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."?setCurrencyId=2\" hreflang=\"en-au\">";
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."?setCurrencyId=4\" hreflang=\"en-ca\">";
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."?setCurrencyId=6\" hreflang=\"en-gb\">";
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."?setCurrencyId=5\" hreflang=\"en-fr\">";
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."?setCurrencyId=5\" hreflang=\"en-de\">";
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."?setCurrencyId=5\" hreflang=\"en-it\">";
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."?setCurrencyId=8\" hreflang=\"en-jp\">";
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."?setCurrencyId=10\" hreflang=\"en-ru\">";
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."?setCurrencyId=11\" hreflang=\"en-kr\">";
$GLOBALS['AdditionalMetaTags'] .= "<link rel=\"alternate\" href=\"".ProdLink($this->_prodname)."?setCurrencyId=9\" hreflang=\"en-sg\">";
// MOD 

ISC_PRODUCT_VIEWS::logView($this->_prodid);

Result

<link rel="alternate" href="https://www.moddiy.com/products/EMS-SpeedPost-Upgrade.html" hreflang="x-default">
<link rel="alternate" href="https://www.moddiy.com/products/EMS-SpeedPost-Upgrade.html" hreflang="en">
<link rel="alternate" href="https://www.moddiy.com/products/EMS-SpeedPost-Upgrade.html" hreflang="en-us">
<link rel="alternate" href="https://www.moddiy.com/products/EMS-SpeedPost-Upgrade.html?setCurrencyId=7" hreflang="en-au">
<link rel="alternate" href="https://www.moddiy.com/products/EMS-SpeedPost-Upgrade.html?setCurrencyId=4" hreflang="en-ca">
<link rel="alternate" href="https://www.moddiy.com/products/EMS-SpeedPost-Upgrade.html?setCurrencyId=6" hreflang="en-gb">
<link rel="alternate" href="https://www.moddiy.com/products/EMS-SpeedPost-Upgrade.html?setCurrencyId=3" hreflang="en-fr">
<link rel="alternate" href="https://www.moddiy.com/products/EMS-SpeedPost-Upgrade.html?setCurrencyId=3" hreflang="en-de">
<link rel="alternate" href="https://www.moddiy.com/products/EMS-SpeedPost-Upgrade.html?setCurrencyId=3" hreflang="en-it">
<link rel="alternate" href="https://www.moddiy.com/products/EMS-SpeedPost-Upgrade.html?setCurrencyId=5" hreflang="en-jp">
<link rel="alternate" href="https://www.moddiy.com/products/EMS-SpeedPost-Upgrade.html?setCurrencyId=10" hreflang="en-ru">
<link rel='canonical' href='https://www.moddiy.com/products/EMS-SpeedPost-Upgrade.html?setCurrencyId=7' />

Troubleshooting

Confirm all tags are correct using below tools:

Leave a Reply

Your email address will not be published. Required fields are marked *