Jump to content

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);
        }
      }  
    }

 

Share this post


Link to post
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.


For a new install or if your store isn't mobile-friendly, get the community-supported responsive osCommerce (Phoenix).

here: on the official osc download page

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

Share this post


Link to post
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...

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×