Product page canonical

Product page canonical

Martin69
New Member
7 0 0

For the Product Variant pages to get actually indexed by Google, they need to get their own canonical.

Current status example:
URL:
https://www.uipkesvloeren.nl/products/visgraat-vloer-helder-wit?variant=44508560425224

has current canonical:
<link rel="canonical" href="https://www.uipkesvloeren.nl/products/visgraat-vloer-helder-wit" />

the correct Canonical should be a Canonical to self:
<link rel="canonical" href="https://www.uipkesvloeren.nl/products/visgraat-vloer-helder-wit?variant=44508560425224" />

Exception:

https://www.uipkesvloeren.nl/products/visgraat-vloer-koraal-wit?variant=44508559343880 is the same page as:
https://www.uipkesvloeren.nl/products/visgraat-vloer-koraal-wit

The variant https://www.uipkesvloeren.nl/products/visgraat-vloer-koraal-wit?variant=44508559343880 should keep his canonical to https://www.uipkesvloeren.nl/products/visgraat-vloer-koraal-wit to prevent duplicate content.

All variant URLs are available to us and we can provide you with a list of ALL ?variant=xxxxxxxxx URLs of ALL product variants.
This also means we have all ?variant=xxxxxxxx exceptions

 

Can someone help us with this?

Replies 3 (3)

Liam
Shopify Staff
2873 312 819

Hi Martin,

 

Just to confirm - you'd like each individual version of a product page that contains the variant ID to be a unique canonical URL?

 

It should be possible to use liquid to set up logic and conditions that when a page is a product page, that the canonical URL has the variant ID appended to it. You could also create a list of exception urls so that the default behaviour keeps for those variants that need the canconical URL without the variant. An example of what this could look like might be something like:

 

{% assign exception_list = 'url1,url2,url3,url4,url5' | split: ',' %}
{% assign current_variant_url = shop.url | append: variant.url %}

{% if template contains 'product' %}
  
  {% if exception_list contains current_variant_url %}
    <link rel="canonical" href="{{ shop.url | append: product.url }}" />
  {% else %}
    <link rel="canonical" href="{{ current_variant_url }}" />
  {% endif %}

{% endif %}

 

In this case when a variant's URL is in the exception list array, it's URL will appear as just the regular shop URL but if it's not in the exception list it would be appended with the variant.url Liquid object. This code would be added where your themes canonical urls are being defined, likely in the theme.liquid file.

 

This is just a basic example of how this could be implemented, so you might need to adjust and test for your own purposes before deploying to any live themes - also it's worth keeping Googles own duplicate content best practices

 

Hope this helps, 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Martin69
New Member
7 0 0

Hi Liam!

Thank you for your efforts to provide us with a solution.
When I implement the code you provide and add some exception URLs, the following happens:
- The exceptions work correctly
https://www.uipkesvloeren.nl/products/visgraat-vloer-koraal-wit?variant=44508559343880 has a canonical to:
https://www.uipkesvloeren.nl/products/visgraat-vloer-koraal-wit, which is correct

- the canonical to self does NOT seem to work:
https://www.uipkesvloeren.nl/products/visgraat-vloer-koraal-wit?variant=44508559311112 should have a canonical to self, but gets a canonical to our homepage ( <link rel="canonical" href="https://www.uipkesvloeren.nl" /> ) Do you have any solutions for this?

We are well aware of duplicate content guidelines and all product variants have unique titles. Google is currently even ignoring some of the product page variant canonicals in favor of indexing these product variants (Canonicals are not directives for Google).

Kind regards,

Martin

ymahfoud
Visitor
1 0 0

Hello Martin,

Did you find a solution for your problem. I currently have the same issue. I appreciate if you can share the solution if you found it.

Kind Regards,

Yamen