Magento – Manually define product page canonical tag

productseourl

Can a product pages canonical tag be manually changed?

I have products which are all the same apart from colour, which is causing duplicate content. So I would like to canonical the other product pages to one single canonical page.

Best Answer

You could create a custom product attribute for this.

Whether a canonical tag should be rendered on a catalog product page is determined in Mage_Catalog_Block_Product_View around the line with

$headBlock->addLinkRel('canonical', $product->getUrlModel()->getUrl($product, $params));.
You could adjust this code that the default canonical is overwritten when the product attribute is filled out in the admin. If not, then it will fallback to the old behaviour.

The proper way to enhance this code is by extending this block from within a custom module.

Related Topic