How can I change the canonical tags on my website pages

Tourist
3 0 1

Thanks @Jason  - it's a relieve we have some control over this.

 

Can you please elaborate on what meta tag is to be used and where it goes?

 

I can get rid of the theme's canonical tag, but what is the proper syntax of the custom meta canonical tag and where do I put it? Do I use the code view of the shopify product description field or is there some if/else trick like in @Lars6' example- where do I put this code?

 

funny - the liquid code he used in his post came through in my email but doesn't show here in the forum - I'll see if it works this time here:

 

{% if product.collections[1].handle contains "sale" or product.collections[1].handle contains "top" or product.collections[1].handle contains "all" %}

<link rel="canonical" href="{{shop.url}}/collections/{{ product.collections[2].handle}}{{product.url}}" />

{% else %}

<link rel="canonical" href="{{shop.url}}/collections/{{ product.collections[1].handle}}{{product.url}}" />

{% endif %}

{% elsif product.collections[0].handle != blank %}

<link rel="canonical" href="{{shop.url}}/collections/{{ product.collections[0].handle}}{{product.url}}" />

{% else %}

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

{% endif %}

{% endif %}
0 Likes
Shopify Partner
7 0 6
Yes I removed some the the lines because it will obviously look different in your theme. As you can see I added some „exceptions“ where some categories shouldn’t be used - e.g. „sale“. 
You need to add the code in the theme.liquid file. 
I am on my computer this evening - if there is still support needed I will copy - Paste this properly in this conversation. 
Best regards Lars 
0 Likes
New Member
1 0 0

I can't see any option to add canonical URL
where i should put my URL? 

0 Likes
Tourist
5 0 2

Hi Lars,

Thanks for sharing this solution. I tried pasting the code in my theme.liquid, but I get the following error:

Liquid syntax error: Unknown tag 'elsif'

Can you help me please?

Best,

Maud

Shopify Partner
7 0 6

Just put the code into the theme.liquid - search for the canonical text within this file. 

0 Likes
Shopify Partner
7 0 6

Send me a PM - we will get this solved! Best regards

Lars

0 Likes
Shopify Expert
62 1 9

Hey Lars,

I've just come across your comment and have been trying to find references as to whether myshop.com/hats/red-hat would be better than simply using myshop.com/red-hat but I can't find any articles that recommend including a collection in the product url or explain how much benefit you get from this practice.

Do you have any references that show that this is the correct/better way to use canonicals?

0 Likes
Tourist
6 0 2

Hello,

I am a store owner and currently, I am trying to Search engine optimize my site. I was checking the canonical tags on every page of my site and found that some duplicate pages have different canonical URLs. For example, a collection page has a canonical URL "https://xenon-store.com/collections/women" but I found some duplicate URLs for this collection page like "https://xenon-store.com/collections/women/xenon-store" or "https://xenon-store.com/collections/women/unstitched" or "https://xenon-store.com/collections/women/unstitched-clothes", How can I edit these pages canonical URLs, Because all pages have different canonical URLs. Does anyone know how to change these canonical URLs? 

Thanks

0 Likes
Tourist
3 0 1

This can easily be done on the collections detail pages.

 

Go to Products > Collections > [click on a collection name] > Scroll to the bottom and click "Edit website SEO" and change the url field at the bottom of the page. You will be changing/updating the collection "handle"

 

Screen Shot 2020-11-27 at 6.48.05 AM.png

 

0 Likes