Canonical URL on Filtered Collection

Topic summary

Main issue: Canonical URLs on filtered collection pages (e.g., /collections/collection-name/product-tag) were including the tag; the goal was to canonicalize to the main collection page and avoid pagination parameters.

Update: A working Liquid approach was shared. It:

  • Starts from canonical_url and removes any query string (e.g., ?page=2).
  • If the template is a collection or blog and current_tags exist, resets the canonical to the base URL (collection.url or blog.url) with the domain.
  • Otherwise leaves the canonical unchanged.

Alternative suggestion: Set the canonical tag directly to the main collection URL via Liquid (collection.url), with the note that Shopify will automatically exclude tag filters and strip pagination from canonical URLs. Guidance to verify via page source was provided.

Outcome: A practical solution is in place, with a simpler alternative offered. No further issues reported; the discussion appears resolved.

Technical notes: Canonical URL is an SEO tag indicating the preferred page version. Filtered collection pages use tags, and Liquid is Shopify’s templating language. Code snippets are central to understanding the fix.

Summarized with AI on December 13. AI used: gpt-5.

Hoping that community can help. I am looking to create some links to a filtered collection page using tags.

So I have a collection URL like

/collections/collection-name/product-tag

Right now my canonical is showing exactly the above although I would prefer to canonicalize to the main page and not include the tag. Is there a way to do this?

My current canonical liquid tag is splitting pagination as well and unsure on syntax to strip the filter, if I even can.


Dropping a solution in that seems to be working.

{%- assign new_canonical_url = canonical_url -%}
{%- if new_canonical_url contains '?' -%}
    {%- assign url_params = new_canonical_url | split: '?' | last -%}
    {%- assign new_canonical_url = new_canonical_url | split: '?' | first -%}
{%- endif -%}
  
{% if template contains 'collection' and current_tags %}
    {%- assign new_canonical_url = collection.url | prepend: '{Domain}' -%}
    
{% elsif template contains 'blog' and current_tags %}
    {%- assign new_canonical_url = blog.url | prepend: '{Domain}' -%}
    
{%- else -%}
    
{%- endif -%}

If you want your filtered collection pages (like /collections/collection-name/product-tag) to point to the main collection page (e.g., /collections/collection-name) as the canonical URL, you can adjust your theme code to do this.

Here’s how:

Steps to Fix Canonical URLs for Filtered Pages:

Update the Canonical Tag Code: In your Shopify theme, go to the theme.liquid or your collection template file. Look for the part where the canonical URL is defined (usually <link rel=“canonical” …>). Replace it with this code:
liquid
Copy code

  1. This ensures the canonical tag always points to the main collection page, no matter which filters or tags are applied.
  2. Fix Pagination Issues: If pagination (like ?page=2) is being added to the URL, this code will still work. Shopify automatically strips the ?page=2 part when generating the canonical URL using collection.url.
  3. Check Your Changes:
  • Go to a filtered collection page on your store.
  • Right-click on the page and select Inspect or View Page Source.
  • Look for the tag. It should now point to the main collection page without any tags or filters.