Post by Mexico123 » Wed Mar 12, 2014 4:01 pm

I’ve created a new OpenCart 1.5.6 store – http://www.example.eu - however, a lot of its pages are identical (in terms of text context) to pages in an old store which is still running – http://www.example.co.uk

With both sites indexed, I’d like to reference all identical pages at the old site by including canonical tags in the new site:
e.g. The “About Us” page at http://www.example.eu/about-us should ideally have something like that in its head section: <link rel="canonical" href="http://www.example.co.uk/delivery"/>
e.g The “Delivery” page at http://www.example.eu/delivery should ideally have something like that in its head section: <link rel="canonical" href="http://www.example.co.uk/delivery"/>

I’m aware how that can be achieved in theory, but cannot apply it in practice. Additionally, while I’m mostly concerned about all the Information-type pages, ideally I’d love to be able to specify the exact pages that will have the canonical tag, something like:

Code: Select all

If (this page is About-Us OR Delivery OR … OR … OR … OR …)
{
Include Canonical Tag of the type <link rel="canonical" href="http://www.example.co.uk/xxxxxxxx"/> , where xxxxxxx changes accordingly, depending on the page.
}
Else
{
Don’t include Canonical Tag
}

Newbie

Posts

Joined
Sat Jul 20, 2013 2:16 pm

Post by anung » Wed Mar 12, 2014 5:12 pm

Try this trick.

In information.php (catalog/controller/information)
put this code

Code: Select all

if ($information_id == '4') {
   $this->document->addLink($this->url->link('information/information', 'information_id=6'), 'canonical');
} elseif ($information_id == '6') {
   $this->document->addLink($this->url->link('information/information', 'information_id=4'), 'canonical');
}
Before this code

Code: Select all

$information_info = $this->model_catalog_information->getInformation($information_id);
Change the information_id as you want. Example above use information_id default OpenCart about as and delivery information on fresh install.

Screenshot the canonical result. Happy coding ;D ;D ;D ;D ;D

User avatar
Active Member

Posts

Joined
Fri Mar 30, 2012 10:32 am
Location - Indonesia

Post by Mexico123 » Sat Mar 15, 2014 5:35 am

Incredible! It works - thank you tons!

One thing though - how can I remove the site's original address and change it to the required completely different one? In other words, in your example we can see href="http://localhost/OC/1561/abous_us" (which I assume comes from the addLink($this->url->link) function) that takes the site's base address and adds the canonical tag to it. What if I want that link to be href=''http://totallyrandomsite.com/about_us" ?

What is necessary to change within the line of code you suggested, so we can put an address of choice, instead of the default site base address?

Code: Select all

$this->document->addLink($this->url->link('information/information', 'information_id=6'), 'canonical');
I've tried to edit the function, but I'm unable to do it properly without breaking the site.

Newbie

Posts

Joined
Sat Jul 20, 2013 2:16 pm

Post by anung » Sat Mar 15, 2014 2:32 pm

If you want to add external url on canonical, try this code

Code: Select all

if ($information_id == '4') {
   $this->document->addLink('http://www.echothemes.com/extensions/blog-manager.html', 'canonical');
} elseif ($information_id == '6') {
   $this->document->addLink('http://www.echothemes.com/extensions/blog-manager.html', 'canonical');
}
Change the 'http://www.echothemes.com/extensions/blog-manager.html' as you want.

Remember the ' ' before and after external url.

Result

User avatar
Active Member

Posts

Joined
Fri Mar 30, 2012 10:32 am
Location - Indonesia

Post by Mexico123 » Sat Mar 15, 2014 3:39 pm

Thank you! That worked like a charm!

Newbie

Posts

Joined
Sat Jul 20, 2013 2:16 pm
Who is online

Users browsing this forum: No registered users and 47 guests