Canonical links for blog articles with tags

SpaPalace
Visitor
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?

 

Replies 5 (5)

simonkane
Shopify Partner
42 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.

bluepaisley
Visitor
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.

Dingchao
Shopify Partner
2 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 }}

 

hermety
Visitor
1 0 0

I have the same issue.

 

I'm trying to create a canonical tag to https://www.theinfluencebooster.com/youtube 

 

Can somebody please recommend the tag and where to install it? 

FatFishMarketin
Shopify Partner
6 0 3

For anyone viewing this post. Be aware if you have multiple blogs this solution will cause canonical 404s.

 

Amend your canonical in the theme.liquid as the following to account for multiple blogs and also your collection pages.

 

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

Joshua Neilly
Fat Fish Marketing