Opinions about this optimization on canonical_url for duplicate products

Ardi94
Pathfinder
101 2 26

Hello,

I have a few duplicate product pages because I wanted to show some variants as separate products on collection pages without messing up the pagination.

To avoid having them flagged as duplicate content, I want to group these products using automatic collections (set to manual sorting and inventory >1). All these products will have a metafield with the collection handle they are related to. Now in my theme, I want to add an if statement that checks if a product has this metafield and if it does, set the canonical_url to the first product's canonical_url instead.

This way if a product is deleted from the collection, all other products that use that canonical_url will be updated to a new URL instead.

Any thoughts on this?

Replies 2 (2)
PaulNewton
Shopify Partner
3486 233 677

Overall goal is workable.

How are you mapping dupes to the canonicals? How does logic know /products/blue-shirt should be products/shirts

(set to manual sorting and inventory >1)

Don't do that that just adds all products to a collection that track inventory.

Either manually add the products or use tags or some other condition that wont create false positives in now or in future.

 

This part reads nonsensically:

 if a product is deleted from the collection, all other products that use that canonical_url will be updated to a new URL instead

Products have no concept of other products there's no built in automation to update other products when a product is deleted.

If a standalone-variant-product-duplicate(SVPD) is deleted that's it no need to point to the canonical product there's nothing to check because nothing exists anyway to do the pointing.

Meanwhile if a canonical-product is deleted then any SVPD that are hardwired to point to the canonical-product now point to a 404.

 

Psuedo 

if product.metafields.seo.SVPD _duplicate
 canonical_product = canonical product finding convention and logic
 OR canonical_product = savp.metafields.seo.canonical_product
 canonical_url = canonical_product.url | filters for formatting URIs
 

<link rel="canonical" href="{{ canonical_url }}">

 

What important thing did you learn this Black Friday?


Answers powered by coffee Buy Paul a ☕ Coffee for more answers or donate to eff.org

Problem Solved? ✔Accept and Like solutions to help future merchants

Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
Ardi94
Pathfinder
101 2 26


Overall goal is workable.

How are you mapping dupes to the canonicals? How does logic know /products/blue-shirt should be products/shirts

(set to manual sorting and inventory >1)

Don't do that that just adds all products to a collection that track inventory.

Either manually add the products or use tags or some other condition that wont create false positives in now or in future.

My mistake, there will be different collections for example shirt-blue, shirt-red, shirt-green are all in one collection called shirt while hat-blue, hat-red, hat-green are on a collection called hat. The reason for inventory > 0* (not 1)  is so if a product is out of stock, the traffic go to the next available product. Essentially, the new canonical_url for other products is automatically updated when the main product changes.

So it will look like this:

Collection name Shirt:

Products:

  • Shirt Blue (Shirt Blue's canonical_url)
  • Shirt Red (shirt blue's canonical_url)
  • Shirt Green (shirt blue's canonical_url)

Collection name Hat:

Products:

  • Hat Blue (Hat Blue's canonical_url)
  • Hat Red (Hat Blue's canonical_url)
  • Hat Green (Hat blue's canonical_url)

 

If Shirt Blue is discontinued for example then the collection will contain only two shirts which then automatically pick a different URL as the main product (I don't have to manually change all of them).

  • Shirt Red (Shirt Red's canonical_url)
  • Shirt Green (Shirt Red's canonical_url)

So there is no reason for products to get updated when another product gets deleted, rather the theme.liquid has an if statement that chooses the URL; so no 404 error. (The only catch is that search engines need time to crawl).