Canonical links for blog articles with tags

Highlighted
New Member
1 0 0

I found the code to put in theme.liquid for proper canonical tags for store products that use tags, but I can't quite get the same effect for blog articles that use tags.  I'm getting tons of duplicate content warnings for any blog article that has tags on them.

 

So I am trying to adapt the code I found for the products with tags soltuion.  Here is what I have:


{% if template contains 'collection' and current_tags %}
<link rel="canonical" href="{{ shop.url }}{{ collection.url }}" />
{% elsif template contains 'blog' and current_tags %}
<link rel="canonical" href="{{ shop.url }}{{ blog.url }}{{ article.url }}" />
{% else %}
<link rel="canonical" href="{{ canonical_url }}" />
{% endif %}

 

But that only prints out a link like this:

https://www.domain.com/blogs/news

 

I need it to output the main link to the main article that the tag is attached to: https://www.domain.com/blogs/news/the-title-of-article

 

I've used this page (and the section here for the blog objects too)

https://help.shopify.com/en/themes/liquid/objects/article

and have tried almost every combination of the various object tags that seem to make sense and I just can't find which combination that will print the original article link in there.

 

Anyone have any ideas?

 

0 Likes
Highlighted
Shopify Partner
2 1 2

Hi SpaPalace,

Just use 

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

for all pages ( included product, collection, blog, or any other pages). Shopify will render proper canonical url for each page.

1 Like
Highlighted
New Member
1 0 0

Hi, can you pls suggest how to create canonical links for few blogs we have. I want few blogs to display canonical of following page.

 

https://bluepaisley.com/pages/rug-cleaning-toronto

 

We have blogs which are closely related to the above page. I want all of them to represent the above link as canonical.

0 Likes
Highlighted
New Member
1 0 0

I want trying to display different options based on the blog tags filter, this is the only way I found to access the full URL.

{{ canonical_url }}

 

0 Likes