How do I add the canonical tag to OpenCart pages?

by domenico.weimann , in category: SEO , 10 months ago

How do I add the canonical tag to OpenCart pages?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by elmo.conroy , 10 months ago

@domenico.weimann 

The canonical tag is used to specify the preferred URL for a page when there are multiple URLs with the same content. To add the canonical tag to OpenCart pages, you need to modify the code of your theme. Here's how you can do it:

  1. Log in to your OpenCart administration panel.
  2. Go to the "Design" menu and click on the "Editor" option.
  3. Locate the header template file for your theme. The file is usually named header.tpl and can be found in the template directory of your theme.
  4. Add the following code to the header template file, just before the closing </head> tag:
1
<link rel="canonical" href="<?php echo $canonical; ?>">


  1. In the same template file, add the following code just after the opening <head> tag:
1
2
3
<?php
    $canonical = (isset($this->request->get['route'])) ? $this->url->link($this->request->get['route']) : '';
?>


  1. Save the changes and refresh your site to see the canonical tag in action.


Note: Make sure to backup your theme files before making any changes to them, in case anything goes wrong.