Jump to content

[Solved] Manual canonical URL for specific products in shop with options activated


Recommended Posts

Dear All

In short the questions is: Can I somehow prohibit prestashop from creating cannonical tags on specific products if I want to keep options activated?

I have a Prestashop 1.7.7.4 instance for a Bike shop under www.lorisvelos.ch. Since I have product options activated for the fram sizes of bikes, Prestashop produces a default canonical tag for every product. This tag, as it should, links from the options-urls back to the main one, e.g. from

https://lorisvelos.ch/velo/vintage-velo/gangurru-classic/gangurru-velo-navy-blue-blau#/26-grosse-46cm

to

https://lorisvelos.ch/velo/vintage-velo/gangurru-classic/gangurru-velo-navy-blue-blau

 

Now for presentation reason, for one bike I would like to both show an article for each color availabe, plus a main one showing all colors. This obviously constitutes duplicate content according to the Google policy and will hurt my SEO.

I do have a module installed where I could add canonical urls to specific products, but then there are two cannonical tags, which according to the google documentation would lead to google ingoring both and thus making things worse.

Thus my question, the solution would be to de-activate the default canonical tag for only the 14 products in question if that is somehow possible (and then insert the canonicals I want for those products using the module I have).

I'm fine with hardcoding it, I'm not code-shy.

 

Looking forward to your opinions, thank you in advance!

 

–––––––––––––––––––––––––––––––––––––––––––––––––––––––

Solved!

I was able to locate the line where the canonical tag was created under theme/YOURTEMPLATE/templates/catalog/product.tpl

There I replaced lines 27-29 that looked like this:

{block name='head_seo' prepend}
    <link rel="canonical" href="{$product.canonical_url}">
{/block}

with this:

{block name='head_seo' prepend}
    {if isset($product.id) && ($product.id != 68) && ($product.id != 66) && ($product.id != 65) && ($product.id != 64) && ($product.id != 63) && ($product.id != 62) && ($product.id != 61) && ($product.id != 60) && ($product.id != 59) && ($product.id != 58) && ($product.id != 57) && ($product.id != 56) && ($product.id != 54) && ($product.id != 51)}
    <link rel="canonical" href="{$product.canonical_url}">
    {/if}
{/block}

 

So in short, I entered an if-then statement, where I told the template to not include the canonical tag for the products with the ID nrs specified. For those products I used the SEO module I purchased and added the Canonical URL I wanted there.

 

Important: Don't remove canonicals without a replacement! Google won't like it

Edited by FlALo
Solved! (see edit history)
Link to comment
Share on other sites

  • FlALo changed the title to [Solved] Manual canonical URL for specific products in shop with options activated

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
×
×
  • Create New...