Update Translatable::MetaTags()

There was an issue which causes `No return tags` issue in hreflang tags added in pages when the page link contains get params.

This link answer https://webmasters.stackexchange.com/questions/110458/how-to-avoid-hreflang-return-errors-with-url-that-contain-parameters?answertab=votes#tab-top suggests just add a canonical tag for the original page rather than adding hreflang tags.
This commit is contained in:
Priyashantha 2018-06-04 12:19:46 +05:30 committed by GitHub
parent 22025df173
commit 7bed02e286
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1726,18 +1726,25 @@ class Translatable extends DataExtension implements PermissionProvider
*/
public function MetaTags(&$tags)
{
$template = '<link rel="alternate" type="text/html" title="%s" hreflang="%s" href="%s" />' . "\n";
$translations = $this->owner->getTranslations();
if ($translations) {
$translations = $translations->toArray();
$translations[] = $this->owner;
foreach ($translations as $translation) {
$tags .= sprintf($template,
Convert::raw2xml($translation->Title),
i18n::convert_rfc1766($translation->Locale),
$translation->AbsoluteLink()
);
if (
($controller = Controller::curr())
&& count($controller->getRequest()->getVars())
) {
$tags .= '<link rel="canonical" href="'.$controller->AbsoluteLink().'" />';
} else {
$template = '<link rel="alternate" type="text/html" title="%s" hreflang="%s" href="%s" />' . "\n";
$translations = $this->owner->getTranslations();
if($translations->count()) {
$translations = $translations->toArray();
$translations[] = $this->owner;
foreach($translations as $translation) {
$tags .= sprintf($template,
Convert::raw2xml($translation->Title),
i18n::convert_rfc1766($translation->Locale),
$translation->AbsoluteLink()
);
}
}
}
}