Hello,
I’m using the Capital theme on my Shopify store, and I’d like product links to use only the canonical URL format:
/products/product-name
Currently, many links include /collections/…/products/…, which creates unnecessary redirects and potential SEO issues.
I couldn’t find any {{ product.url | within: collection }} in the theme files, so I assume URLs are generated differently in Capital.
Could you let me know how to force product links to use only the canonical /products/… path, or where I can modify this in the theme?
Thanks in advance,
@Andre1689 , hey, thanks for posting here.
Can you please share some code file screenshots to identify the code, or share the theme files?
Hi @Andre1689
To ensure all product links in your Shopify store using the Capital theme use only the canonical URL format (__/products/product-name)-and not the longer /collections/…/products/… version-you’ll need to adjust your theme’s code so product links always point directly to the canonical product URL.
Here’s how to do it:
1. Backup Your ThemeBefore making any changes, duplicate your theme for safety.
Go to Online Store > Themes > Actions > Duplicate.
2. Find the Link Code in Your Theme FilesThe product links on collection pages are usually generated in one of the following files:
snippets/product-grid-item.liquid
snippets/product-card.liquid
sections/collection-template.liquid
Or similarly named files (the exact name may vary by theme).
Use the code editor’s search (Ctrl+F or Cmd+F*)* to look for product**.url** or within: collection in these files.
3. Update the Product Link CodeWhat to look for:
The code for product links often looks like this:
or similar.
What to change:
Replace it with:
This change will force all product links to use only the canonical /products/product-name URL, regardless of where they appear.
If you don’t see within: collection:
Some themes (like Capital) may already use {{ product.url }} or may generate links differently. In that case, ensure every instance of product links in your collection, featured product, or related product snippets uses {{ product.url }} and not a custom build that includes collection handles.
4. Test Your StoreGo to a collection page and click on a product.
The URL in the browser should now be /products/product-name without any /collections/…/ path.
5. Set Up Redirects (If Needed)If your store has already been indexed with the longer URLs, set up URL redirects:
Go to Online Store > Navigation > URL Redirects.
Redirect from /collections/collection-name/products/product-name to /products/product-name.
6. Monitor for IssuesCheck your site for broken links or unexpected behavior.
Monitor Google Search Console for crawl errors after making these changes.
Hello @PROSPRO
Here is a screenshot of me searching for product.url in my code, but no results came up. Am I searching in the right section?
@Andre1689 NO mate, here you just search file name, not code.
Hi @BiDeal-Discount ,
Sadly I’m not able to find any of those 3.
Here are 2 screnshots of what I actually have in sections and snippets
Is that because of the capital theme that I’m using?
Thanks for your help !
Oh I see thanks so i would have to do a CTRL+F in a code page and search for “product.url” or “within: collection”
I did look into most of them this afternoon but wasn’t able to find it.
@BiDeal-Discount encouraged me to look into those sections:
snippets/product-grid-item.liquid
snippets/product-card.liquid
sections/collection-template.liquid
I was able to find sections that resemble them like for exemple: collection.liquide in sections but no “product.url” or “within: collection”
@Andre1689 , can you please share the files for a fast solution?
I found it under snippet → “product-item”.
I had to make 3 changes:
- Product image link
Modified line:
{% assign image_link = item.url | within: collection %}
Replaced with:
{% assign image_link = item.url %}
- Product title link
Modified line:
{{ item.title }}
Replaced with:
{{ item.title }}
- “View product” button link
Modified line:
{{ “products.product.view_product” | t }}
Replaced with:
{{ “products.product.view_product” | t }}
Hello,
I found it!
I found it under snippets → “product-item”.
I had to make 3 changes:
- Product image link
Modified line:
{% assign image_link = item.url | within: collection %}
Replaced with:
{% assign image_link = item.url %}
- Product title link
Modified line:
{{ item.title }}
Replaced with:
{{ item.title }}
- “View product” button link
Modified line:
{{ “products.product.view_product” | t }}
Replaced with:
{{ “products.product.view_product” | t }}