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.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.Sign up to join this community
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.
Yes you can manually define the product canonical url;
Edit the product in Magento admin and under the "Design" options add somthing like this to the "Custom Layout Update" section.
<reference name="head"> <action method="addLinkRel"> <rel>canonical</rel> <href>http://www.domain.com/page</href> </action> </reference>
1) First create the product's custom attribute name is : custom_url
2) Enter the relative url of product(ie: url key). example: abc.html
3) In product listing or at homepage wherever you want to show the products. Just get this attribute value from product object.It will definitely work. Replace product original url with this custom product url.
You can easily find the code for getting attribute value on internet.
While it sounds like Tim Hofman / Rushvi's solution would be a cool customization to make overwriting product canonicals easier to manage, I found another solution that allows you to manually overwrite an existing canonical for products (or other pages that allow you to insert Custom Layout Update XML).
This worked perfectly for me, as we have "Use Canonical Link Meta Tag For Products" set in Configuration > Catalog > Catalog > Search Engine Optimizations.
This XML first removes the existing canonical link and then adds your override!
<reference name='head'> <action method="removeItem" block="head"> <item>link_rel</item> <name>URL-FROM-EXISTING-CANONICAL</name> </action> <action method='addLinkRel'> <rel>canonical</rel> <href>NEW-URL-FOR-CANONICAL-OVERRIDE</href> </action> </reference>