Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Canonical Link Question


Recommended Posts

So I was updating SEO on my site and then I noticed my main home page doesn't have a canonical link.  I also noticed that category pages that contain more subcategories also do not have a canonical link.

The code below from / includes/modules/header_tags/ht_canonical.php  is what creates the canonical link.  

Can someone explain to me why the main index.php page and categories that don't have products are not included in this code?  I would think they would still need canonical links....

 

 function execute() {
      global $PHP_SELF, $cPath, $oscTemplate, $category_depth;

      if (basename($PHP_SELF) == 'product_info.php') {
        $oscTemplate->addBlock('<link rel="canonical" href="' . tep_href_link('product_info.php', 'products_id=' . (int)$_GET['products_id'], 'NONSSL', false) . '" />' . PHP_EOL, $this->group);
      } elseif (basename($PHP_SELF) == 'index.php') {
        if (isset($cPath) && tep_not_null($cPath) && ($category_depth == 'products')) {
          $oscTemplate->addBlock('<link rel="canonical" href="' . tep_href_link('index.php', 'view=all&cPath=' . $cPath, 'NONSSL', false) . '" />' . PHP_EOL, $this->group);
        } elseif (isset($_GET['manufacturers_id']) && tep_not_null($_GET['manufacturers_id'])) {
          $oscTemplate->addBlock('<link rel="canonical" href="' . tep_href_link('index.php', 'view=all&manufacturers_id=' . (int)$_GET['manufacturers_id'], 'NONSSL', false) . '" />' . PHP_EOL, $this->group);
        } 
      }
      else {
        $view_all_pages = array('products_new.php', 'specials.php');
        if (in_array(basename($PHP_SELF), $view_all_pages)) {
          $oscTemplate->addBlock('<link rel="canonical" href="' . tep_href_link($PHP_SELF, 'view=all', 'NONSSL', false) . '" />' . PHP_EOL, $this->group);
        }
      }  
    }

 

Link to comment
Share on other sites

A canonical link is used to give a single name to a page that may be accessed via different paths or with different parameters, eg. products can be in more than one category so there are different paths to the same product.

The canonical link gives a single name for that page so it doesn't look like duplicate content to search engines.

Categories can only be in one category, and the views of them don't have paging, so those aspects of index.php don't need a canonical link.

Contact me for work on updating existing stores - whether to Phoenix or the new osC when it's released.

Looking for a payment or shipping module? Maybe I've already done it.

Working on generalising bespoke solutions for Quickbooks integration, Easify integration and pay4later (DEKO) integration at 2.3.x

Link to comment
Share on other sites

20 hours ago, BrockleyJohn said:

A canonical link is used to give a single name to a page that may be accessed via different paths or with different parameters, eg. products can be in more than one category so there are different paths to the same product.

The canonical link gives a single name for that page so it doesn't look like duplicate content to search engines.

Categories can only be in one category, and the views of them don't have paging, so those aspects of index.php don't need a canonical link.

Thank you.  That makes sense.

 

However, shouldn't the home page have a canonical link?  The current code does NOT provide a canonical link for your homepage...

Link to comment
Share on other sites

The proper way to setup the home page is to add redirect code to the .htaccess file to force the links to use one format, like www or non-www.  In that case, since there is only one possible url, a canonical tag is not needed.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...