SEO, AdWords, affiliates, advertising, and promotions
I have a blog I use on my Shopify store. I made an agreement with a third party blog to republish some of their content on my blog but they’re requesting their url to be in the meta tag description of my website and not mine, which is fine. My question is, how would I go about customizing my blog canonical url meta tag to show their url and not mine? Thanks
If you look in your theme's main layout template theme.liquid, you should see this in the <head> section:
<link rel="canonical" href="{{canonical_url}}">
Use something like ShopifyFD to add a metafield to each 3rd-party article that contains the canonical URL of the article. Then change that line above to something like this:
{% if template contains 'article' %}
{% if article.metafields.metadata.canonical_url %}
<link rel="canonical" href="{{article.metafields.metadata.canonical_url}}">
{% else %}
<link rel="canonical" href="{{canonical_url}}">
{% endif %}
{% else %}
<link rel="canonical" href="{{canonical_url}}">
{% endif %}
Adjust the code to the namespace and key you're using for the metafield. And make sure to check that the canonical tags are still being output correctly on all your store's other pages, just to be sure there's no bug in the modified code.
Update: I editted my syntax below and everything is now working. Below is now my correct syntax.
Hi Thomas,
Thanks for taking the time to answer my question. I understand your logic but I'm not overly familiar with Liquid. I've downloaded ShopifyFD and added my metafields but I can't access the values.
namespace: mywebsite
key: myurl
value: http://mywebsite.com
My question is, how do I access the value?
The code:
{% if template contains 'article' %}
{% if article.metafields.mywebsite.myurl%}
<link rel="canonical" href="{{article.metafields.mywebsite.myurl}}">
{% else %}
<link rel="canonical" href="{{canonical_url}}">
{% endif %}
{% else %}
<link rel="canonical" href="{{canonical_url}}">
{% endif %}
I would explicitly set your conditional statement like this vs assuming a true/false response.
{% if article.metafields.mywebsite.myurl == blank %}
nothing!
{% else %}
has something!
{% endif %}
Jason, thank you for the help
Below is the correct syntax:
{% if template contains 'article' %}
{% if article.metafields.mywebsite.myurl == blank %}
<link rel="canonical" href="{{canonical_url}}">
{% else %}
<link rel="canonical" href="{{article.metafields.mywebsite.myurl}}">
{% endif %}
{% else %}
<link rel="canonical" href="{{canonical_url}}">
{% endif %}
Yeah, my bad for not actually testing the code in a theme. Checking for blank instead of true/false is obviously the correct way to do it. Thanks, Jason!
No, thank you Thomas.
User | RANK |
---|---|
5 | |
5 | |
4 | |
4 | |
3 |
As a business owner, have you ever wondered when your customer's first impression of yo...
By Skye Jun 6, 2023We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023