All things Shopify and commerce
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
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.
<link rel="canonical" href="{{ canonical_url | split: '?' | first}}">
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}' -%}
<link rel="canonical" href="{{ new_canonical_url | split: '?' | first }}">
{% elsif template contains 'blog' and current_tags %}
{%- assign new_canonical_url = blog.url | prepend: '{Domain}' -%}
<link rel="canonical" href="{{ new_canonical_url | split: '?' | first }}">
{%- else -%}
<link rel="canonical" href="{{ new_canonical_url | split: '?' | first }}">
{%- 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:
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
<link rel="canonical" href="{{ collection.url | within: collection }}" />