Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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?
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.
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.
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 }}
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?
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 %}
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024