General version canonical tag in joomla 3

Popular automatic website translation tool

General version canonical tag in joomla 3

Postby pacowilson » Wed May 07, 2014 7:29 am

Hello guys,

We are using the joomla 3 and zoo component. We want to modify the canonical tag for zoo catagery/item.

We want to insert language code into the canonical tag.
For example: <link href="http://www.domain.com/item/iphone7-smartphone.html" rel="canonical"/>
Insert the language code: <link href="http://www.domain.com/es/iphone7-smartphone.html" rel="canonical"/>

Below is the code for zoo:
// add canonical
if ($this->app->system->document instanceof JDocumentHTML) {
$this->app->system->document->addHeadLink(JRoute::_($this->app->route->item($this->item, false), true, -1), 'canonical');
$headData = $this->app->system->document->getHeadData();
foreach ($headData['links'] as $key => $value) {
if($value['relation'] == 'canonical' && $key != JRoute::_($this->app->route->item($this->item, false), true, -1)) {
unset($headData['links'][$key]);
}
}
$this->app->system->document->setHeadData($headData);
}

Please provide the solution to me, thank you.
pacowilson
 
Posts: 24
Joined: Thu Feb 23, 2012 5:37 pm

Re: General version canonical tag in joomla 3

Postby pacowilson » Wed May 07, 2014 9:08 am

By the way, it seems the pro version doesn't translate the Open Graph Tags :cry:
pacowilson
 
Posts: 24
Joined: Thu Feb 23, 2012 5:37 pm

Re: General version canonical tag in joomla 3

Postby Edvard » Wed May 07, 2014 12:04 pm

Hi,

First you need to change the .htaccess rules to add the possibility of language detection:

Code: Select all
# gtranslate config
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/([a-z]{2}|zh-CN|zh-TW)/(.*)$ /$1/$3 [R=301,L]
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/([a-z]{2}|zh-CN|zh-TW)$ /$1/ [R=301,L]
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/(.*)$ /gtranslate/translate.php?lang=$1&url=$2&glang=$1 [L,QSA]
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)$ /gtranslate/translate.php?lang=$1&glang=$1 [L,QSA]


After that you will be able to identify the selected language by $_GET['glang'] variable.

The canonical link is generated by JRoute::_($this->app->route->item($this->item, false), true, -1) function call. You need to add the language code inside of it. The easiest way is to replace it with:

str_replace('domain.com/', 'domain.com/' . (empty($_GET['glang']) ? '' : $_GET['glang'] . '/'), JRoute::_($this->app->route->item($this->item, false), true, -1))

BTW. The canonical translation is integrated into our Enterprise version which allows also URL translation.

Open graph tags are not translated.

Let me know.

Thanks!
Regards,

Edvard Ananyan - GTranslate Team

Please leave your feedback on your CMS plugin directory. It is very important for us!
Google Translate Joomla
Google Translate WordPress
Google Translate Drupal
Edvard
Site Admin
 
Posts: 4183
Joined: Mon Jun 28, 2010 1:54 pm
Location: Yerevan, Armenia


  • Related Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 0 guests

2GLux