Canonical in OpenCart 2x

One of the ways to add rel='canonical' with a link to the current page (namely the current one), yes, such perversions also come across...

Categories Page

Edit catalog/controller/product/category.php, in the public function index() block, after $this->load->model('tool/image'); add

if (isset($this->request->get['page'])) {
    $page = $this->request->get['page'];
    $pathx = explode('_', $this->request->get['path']);
    $pathx = end($pathx);
	$this->document->addLink($this->url->link('product/category', 'path=' . $pathx . '&page='. ($page), true), 'canonical');
} else {
    $page = 1;
}

Manufacturer's page

Edit catalog/controller/product/manufacturer.php, in the public function index() block, after $this->load->model('tool/image'); add or edit code, if any

if (isset($this->request->get['manufacturer_id'])) {
	$page = $this->request->get['page'];
	$this->document->addLink($this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&page='. ($page), true), 'canonical');
}

Or the second option, in the public function info() { block, approximately on line 97 in the construction

if (isset($this->request->get['page'])) {
	$page = $this->request->get['page']; 
} else {
	$page = 1;
}

add

if (isset($this->request->get['page'])) {
	$page = $this->request->get['page'];
	if (isset($this->request->get['manufacturer_id'])) {
		$this->document->addLink($this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . '&page=' .($page)), 'canonical');
	} 
} else {
	$page = 1;
}

Information page

Editing the file catalog/controller/information/information. Since such pages are usually without pagination, you can get by with pasting the code

if (isset($this->request->get['information_id'])) {$this->document->addLink($this->url->link('information/information', 'information_id=' . $this->request->get['information_id']), 'canonical');}

in the public function index() { block, after the breadcrumb declaration condition $data['breadcrumbs'][] = array( *** );

Standard contact page (contact-us)

Editing the catalog/controller/information/contact.php file. In the public function index() { block, after declaring the array of breadcrumbs, add the line

$this->document->addLink($this->url->link('information/contact'), 'canonical');

Простий текст

  • Не дозволено жодних HTML теґів.
  • Рядки й абзаци переносяться автоматично.
  • Адреси вебсторінок та адреси електронної пошти автоматично перетворюються у посилання.
Код мови коментаря.