In this tutorial i will show you how to put the meta tag <meta name="robots" content="noindex,follow"> on specific pages in OpenCart.
Q.A:
Why would i do this?
Out of the box is OpenCart pretty SEO-friendly, but you can always do this better with some tricks and fixes. This will put the meta tag on specific pages such as onsite search results. This is crucial for SEO purposes to avoid certain stuff like duplicate content and low quality pages. If you do not do this it can result bad SEO and in worst cases you can get penalized for bad content.
Why not use /disallow in robots.txt?
I have seen lost of posts in this forum on this case of problem, the thing is that the robots.txt do not "unindex" your pages and many of the search engines do ignore this file. And Google has announced that noindex,follow meta tag is the code you need.
The Tutorial:
To make this happen you need to code some in the core files. You can also make this with a VqMod file if you're not comfort with coding inside the core files.
Lets get going.
Find this file:
catalog/controller/common/header.php
Find line:
Code: Select all
$this->data['links'] = $this->document->getLinks();
Code: Select all
$this->data['robots'] = $this->document->getRobots();
system/library/document.php
Find line:
Code: Select all
private $description;
Code: Select all
private $robots;
Code: Select all
public function setDescription($description) {
Code: Select all
public function setRobots($robots) {
$this->robots = $robots;
}
public function getRobots() {
return $this->robots;
}
catalog/view/theme/YOUR_THEME/template/common/header.tpl
Find line:
Code: Select all
<?php if ($description) { ?>
<meta name="description" content="<?php echo $description; ?>" />
<?php } ?>
Code: Select all
<?php if ($robots) { ?>
<meta name="robots" content="<?php echo $robots; ?>" />
<?php } ?>
This will be an example to put noindex,follow on search page.
Find this file:
catalog/controller/product/search.php
Find:
Code: Select all
$this->load->model('catalog/category');
Code: Select all
$this->document->setRobots('noindex,follow');
Hope this will help some people that want to tweak OpenCart even more in SEO purposes. Please check out the extension parts of this. Cause i am in work to make a real module for this.
/Mijo Media