Setting Canonicals on Collection Filters

nathanhuffhines
Tourist
9 0 5

Right now, if I filter a collection page:

 

/collections/product-series?filter.p.product_type=Product+X

 

It canonicals back to:

 

/collections/product-series

 

What if I want to make the filtered results into an organic landing page so that it self-canonicals? Is that possible? I don't want to do it for all facet/filters but I would like to do it for some of them.

 

Thanks!

Replies 5 (5)

mics
Trailblazer
172 12 32

 

Yes, it is possible to set canonical URLs for filtered collection pages in Shopify. Here's how you can do it:

  1. Identify the URL structure for your filtered collection pages: In your example, the URL for the filtered collection page is: /collections/product-series?filter.p.product_type=Product+X. You'll need to identify the URL structure for your filtered collection pages so you can set the canonical URL correctly.

  2. Add the following code to the head section of your theme.liquid file:

 

 
{% if template == 'collection' and collection.handle == 'product-series' and current_query contains 'filter' %} <link rel="canonical" href="{{ collection.url }}{{ current_query }}"> {% endif %}
 

This code checks if the current page is a collection page with the handle "product-series" and if it contains a filter query string. If both conditions are met, it sets the canonical URL to the current collection URL with the query string included.

  1. Customize the code to match your URL structure: You'll need to customize the code to match the URL structure for your filtered collection pages. Replace 'product-series' with the handle of your collection and update the current_query variable to match the query string parameter used in your URL structure.

By adding this code to your theme.liquid file, your filtered collection pages will self-canonicalize based on the URL structure you've defined. This will help ensure that search engines understand which page is the canonical version, which can help improve SEO for your store.

banned
Asakusa
Visitor
2 0 1

Hi there,

 

I am not sure what do to with your response which looks by the way super accurate. : D

 

Basically, I have many filtered pages like:

> /collections/cbd-pour-animaux/dosages-legers

> /collections/cbd-pour-animaux/dosages-intenses

> /collections/cbd-pour-animaux/poids-1-a-5-kg

 

And I want all the above pages to be canonised pointing at page (to avoid duplicate content) :

/collections/cbd-pour-animaux

 

Based on that, can you tell me what code I need to put on the head section of your theme.liquid file ?

 

Thanks you

Yann

mrhandsome
Tourist
9 0 0

I am looking for a solution for the exact same issue 

pawankumar
Shopify Partner
424 43 77

I think, product tag can help you like
If you have some products with tag tag-a then this /collections/your-collection/tag-a will show all these products and it has its own canonical url
Then you can create a navigation of such links and then call it.
Please check if it helps!
Thanks!

- Need a Shopify developer? Chat on WhatsApp +91-9467121281
- Coffee Tip: Buymeacoffee  | Email: thepkpawankumar@gmail.com
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Best regards,
Pawan
Asakusa
Visitor
2 0 1

Hi there,

 

I am not sure what do to with your response.

 

Basically, I have many filtered pages like:

> /collections/cbd-pour-animaux/dosages-legers

> /collections/cbd-pour-animaux/dosages-intenses

> /collections/cbd-pour-animaux/poids-1-a-5-kg

 

And I want all the above pages to be canonised pointing at page (to avoid duplicate content) :

/collections/cbd-pour-animaux

 

Based on that, can you tell me what code I need to put on the head section of your theme.liquid file ?

 

Thanks you

Yann