Last Updated on June 3, 2019
Canonicals urls are an essential part of avoiding duplicate content in an ecommerce store, and should be added to all pages and products by default.
However, the Opencart CMS doesn’t include any canonical urls for the Homepage or the Category / Sub-category pages, leading to lots of duplicate content issues, and potentially causing issues in your SEO efforts.
I’m going to show you exactly which canonicals you need, and how to easily insert them into your store using a FREE VQMOD file.
What is a canonical url and why do you need one?
Simply put, a canonical link points to the “proper url location” of a page, to avoid Google indexing duplicate page urls, and maintain the link equity of your website.
Examples of Duplicate Content in Opencart
There are plenty of examples in Opencart of duplicate content that can harm your websites Google rankings.
For example if you can visit a product via different routes such as:
- Homepage -> Category -> Product
- Homepage -> Category -> Sub-category -> Product
- Homepage -> Product
These urls will all have different url paths:
- http://domain.com/category/product
- http://domain.com/category/sub-category/product
- http://domain.com/product
When Google crawls your website, it follows all of these variations, and so each of these links will be crawled, and counted as a different page.
Duplicate Content And Google Panda Penalties
Google HATES duplicate content with a passion, particularly duplicate content on the same website.
They have an algorithm dedicated to penalising websites for this, called Panda, which is notorious for not just harming the pages with duplicate content, but bringing the entire websites rankings down.
Fix Duplicates with a Canonical Link
Luckily there is a fantastic way to tell Google that each of these pages are the same, and then tell them which one you would like to count as the “proper location”.
That’s called a canonical link, and it looks like this:
<link href="http://domain.com/product" rel="canonical" />
In our example, if this was added to the product page as a canonical link, then it tells Google that the Homepage -> Product version of this url is the only one that should be indexed.
This fixes the duplicate content, as Google only indexes one version of the page, keeping all of your indexed content unique, and resulting in higher rankings.
Stop Losing Link Equity With Canonicals
Canonicals also prevent you from spreading your link equity too thinly over your website. For example if someone links to these two pages:
- http://domain.com/product
- http://domain.com/category/product
Then without a canonical url, you will have one link to each page, and two competing pages that can cause keyword cannibalisation.
With a canonical url, the link pointing to the non-canonical version of the page will be counted towards the rankings of your main page, helping it rank even better in Google for its target keywords.
How to Add a Canonical Link to Your Opencart Homepage
The homepage of your online store is the single most important page from an SEO perspective.
It will normally have the greatest amount of inbound links, and contain internal links to your other most important pages, spreading the authority to the rest of your website.
So what’s the problem?
Without a canonical, multiple variations of the homepage url can be indexed in Google, urls such as:
- http://domain.com
- http://domain.com/index.php
- http://domain.com?test=1234
- http://domain.com?product=category
These will all display the same page (your homepage), but because they are separate urls Google treats them as unique pages.
The Code To Add a Homepage Canonical in Opencart
You will need to edit one of your website files via FTP or file manager to do this. Alternatively for a better way to implement it, you can use the FREE VQMOD file at the end of this guide.
First navigate to: catalog/controller/common/ and open the file home.php.
Next you will want to find the line:
$this->document->setDescription($this->config->get('config_meta_description'));
And below it, add the following code:
$this->document->addLink('http://YOURDOMAIN.com/', 'canonical');
You will need to replace the example url with the homepage url of your Opencart store.
How to Add a Canonical Link to Your Opencart Category Pages
As mentioned above, your category pages require canonicals to ensure no duplicate paths are indexed, and to maintain your link equity.
This is a particular problem with category pages that contain product filters, as they often create new urls when you choose a filter.
For example when you filter the product list by Price Low > High in Opencart the url looks like this:
http://opencart.matt-jackson.com/desktops?sort=p.price&order=ASC
Without a canonical, this will index as a new url, and cause a Google Panda penalty from duplicate content as mentioned previously
The Code for an Opencart Category Canonical
It’s quite simple to add this code to the category controller, and produce your own category canonical links. HOWEVER, if you would rather have the simple and FREE version of doing it, see the free VQMOD file attached at the end of this post.
Via FTP, visit this location in your store: catalog/controller/product/ and open the file category.php.
Find the following line of code:
$this->document->setDescription($category_info['meta_description']);
And below it add this code:
$this->document->addLink($this->url->link('product/category', "path=".$this->request->get['path']), 'canonical');
This will produce the canonicals on every category and sub-category page.
Free Vqmod To Insert Homepage & Category Canonicals
Here is your free SEO loophole, a VQMOD file that automatically inserts the canonical for the homepage url, and your category urls.
Simply like or subscribe to gain access to the file below.
Hi Matt, good article. But i have found another bug.
I see opencart demo of a subcategory on this page
demo.opencart.com/index.php?route=product/category&path=25_28
The canonical is correct. But if i delete 25 and i write it
demo.opencart.com/index.php?route=product/category&path=28
i can see the same page (duplicate content) and a different canonical.
It’s possible to solve it? I think that to be sure 100% we need to solve it, right?
Thanks so much !!!
Antonio
Hi Antonio, I’ve checked the demo urls you’ve pasted and they both have the same canonical url:
demo.opencart.com/index.php?route=product/category&path=28
This means that Google won’t treat them as duplicate content.
All the best.
Matt
Hi Matt,
Wah thanks it’s worked in opencart v1.7. Many Thanks.
But when I try in opencart 2.2 it’s not worked. Any suggestion ?
Thanks.
Hi Eko, I think the categories in 2.0 have a canonical feature enabled by default, and the homepage canonical should work in the same way as the article.
If you’re still struggling then feel free to email me: info@matt-jackson.com
Hi I am using opencart version 1.56 , I am not able to download vqmod version of canonical module.
can you email me on anshul.udapure@gmail.com
Sure, I’ve emailed you.
Hello!
I think about to add in canonical for pagination link to page with all products of current category. Some link like Show all. But, I did not find the way how to do it.
I thought about something like this
mysite.com/somecategory/?limit=9999
But I am not sure.
Maybe you did it or can help me to find better method?
Thank in advance.
Hi Anna,
The ideal solution is to set all pagination pages (page 2, 3, etc) to noindex, follow.
This means that Google will read the content (links to products, etc) but it will not index the pages.
To do this in Opencart, I think you need to do some custom coding, a temporary solution would be to block the pagination in the robots.txt file such as:
Disallow: /*&sort
Disallow: /*&limit
Disallow: /*?limit=
But in the long term it’s better to have them crawled but not indexed.
I’ll have a look for a plugin that works for this and get back to you.
All the best.
Matt
Hi Matt,
Did you manage to figure out a mod for the category page 2/3/4/5 duplicate tags? at the moment, we have managed to solve these issues in a robots.txt file, however it would be nice to get a permanent fix for the website so it doesn’t see this as a duplicate tag.
Thanks in advance
Hi David,
Sorry for the late reply.
I think realistically it’s ok to index the page 2/3 etc urls as long as you have the correct rel=”next” rel=”prev” tags in place.
You still want them to crawl the links to product pages, and so you don’t really want to completely block the other pages unless you’re getting the wrong variation ranking in SERPs.
If you want me to look at your site, then feel free to email me at info@matt-jackson.com
Hello will i see a big difference in the ranking?
I guess i have to get better ranking just by ading this.
I mean it was even confusing for me the way opencart handles url’s
It’s all relative to how many problems you have, the quality of your site, etc. But I would definitely expect to see a rankings improvement from fixing duplicate content problems on any website.
Hi Matt, im wondering does the opencart 3.0.0.2 have default canonical links implemented already? I think it does, except for the homepage if im not mistaken. Can you confirm this?
Thanks
Hi Rock, it also has an incorrect sub-category canonical by default, example from their demo: https://demo.opencart.com/index.php?route=product/category&path=18_46
You can see that the example canonical is missing the 18_ part of the url, which represents the main category. I would advise that the canonical includes the main category.
You can email me or reply if you have further questions.
Cheers
Matt
Hi;
Thanks for your great article.
I have an issue and i hope you would help me.
I’ve done what did you said and I’ve added codes in my controller in the write place,
But unfortunately there is no link appearing in my frontend.
As i know we are adding a Link with out controller to show in frontend but there is no call in header.tpl .
What should I do ?
Thanks 🙂
Hi Bahram, send me an email with the site and I’ll take a look for you.
I have add code in my opencart version 3.0.2.0, But not getting solution, Can you please suggestion.
I think for OC 3.xx it’s done slightly differently.
Your header.twig file should contain this code:
{% if canonical %}
{{canonical}}
{% endif %}
Then the line you want to have in your controller (instead of the one mentioned in the article) is this:
if (isset($this->request->get[‘route’])) {
$this->document->addLink($this->config->get(‘config_url’), ‘canonical’);
}
Let me know if that works! You can always email me at info@matt-jackson.com
Thanks for your valuable insights. Using 3.0.3.2 and say your comment about
{% if canonical %}
{{canonical}}
{% endif %}
should be in the header.twig. Are you saying this needs to be added to the header.twig or should this already be in there. If it needs adding, can you confirm where to place in the twig file and here the twig file is located. Thanks so much.
Hi Kay,
Thanks for your comment. I said that the {% if canonical %} ..etc code should be in your header.twig already.
The new code should be added to the controller file called “category.php” found at catalog/controller/product, after this line: $this->document->setDescription($category_info[‘meta_description’]);
The new code to add is: if (isset($this->request->get[‘route’])) {
$this->document->addLink($this->config->get(‘config_url’), ‘canonical’);
}
Let me know if that works for you.
Cheers
Hello Matt,
I don’t find this code in header.twig. where should I add it.
{% if canonical %}
{{canonical}}
{% endif %}
Hi Wael,
I don’t quite understand what you mean, could you explain further over email? info@matt-jackson.com
Hi Matt – thanks for this. Will it work with opencart multistores, running on different domains?
i.e. following your instructions for the home.php, if I put the domain of the installation site there, will it work in the multistores with different domain names?
—-
First navigate to: catalog/controller/common/ and open the file home.php.
Next you will want to find the line:
$this->document->setDescription($this->config->get(‘config_meta_description’));
And below it, add the following code:
$this->document->addLink(‘http://YOURDOMAIN.com/’, ‘canonical’);
—–
Many thanks
Hi Debbie,
I haven’t tested it with a multistore, but if you’ve implemented it I can check to see if it’s active, just send me an email with the sites – info@matt-jackson.com
Hey. Can I add “Canonicals” to the filter page links? really needed
Hi Bu, in most situations these will canonical back to the main category page.
If not, then you can block the URL variations in the robots.txt if they follow a pattern and don’t conflict with other urls.
Hi Matt,
Thank you for your awesome article! Just wondering if there is a way to check if the page is category or product or else then we can have a canonical tag according to that? So I can just put that code into head.tpl file without having to config each custom code for homepage, about page, category pages and product pages?
Hi Anna, I recommend the extension called “Path Manager” be Geekodev, it’s really good for controlling the canonical links in Opencart.
Thank you, Finding your post saved all the effort, saved the day.
I wish you all the good luck. You have quality manners.
I recommend this for all who use opencart 2.3.0.2 – It works great !
Best,
D.K.