How to create conditional Canonical tag in CMS

Hi there —

We’re a news publisher, and sometimes we republish articles, with permission, from publishing partners. We want to make sure that we’re adding a Canonical tag so Google knows who originally published the story — and doesn’t ding us for duplicate content.

So I followed the process for setting up Canonical tags in the CMS (using a custom version) of the details published in Item #7 in this blog post: https://webflow.com/blog/seo-and-webflow-the-essential-guide

The only problem is that when I test a page (https://www.goodgoodgood.co/articles/sidney-poitier) in this Canonical Link checker (https://seositecheckup.com/analysis) — it tells me that we have duplicate tags.

I don’t see anywhere else that I have canonical tags written into our Schema, so I have to assume this is the Global Canonical Tag URL setting inside of Webflow’s SEO settings? (But please correct me if I’m wrong.)

I’m nervous to just turn that off — because I don’t want Google to get confused about which version of my site to index. (www. vs non-www. — but also… we have like 13 Custom Domains that are connected to Webflow (like goodnewspaper.org) and I want to make sure those also don’t confuse Google.

Do you have advice on how to best proceed?
I’m looking for the ability to tell Google which articles are republished and deserve to point somewhere else for the Canonical… while also telling Google what the canonical is for our site for every single other page/post.

Thank you for your help!


Here is my site Read-Only: [LINK]1
(how to share your site Read-Only link)

(If it helps, the code for the Canonical Tag is under the “Articles Template” in the “CMS Collection pages”)

Hi @brandenh thanks for the post on the canonical tag.

The global canonical tag in Webflow if used will add the tag to all pages on your site, regardless if you have some canonical tag added at page settings, such as what is happening on the articles page:

Shared with CloudApp

If you wish to get rid of the duplicates, then I would disable the Global Canonical SEO tag and instead add manual canonical tags using custom code for all static pages and all collection page templates and use page settings only to add the canonical url.

On the articles page template, it looks like you are getting the url from a collection field, on static page settings in the Head of each page you would provide a static page url to the custom domain url you wish to use as the canonical url.

After setting up your canonical tags in the head of page or template page settings, then disable the Global canonical tag setting in your SEO tab of project settings and republish the site.

I hope this helps.

This is incredibly helpful, Dave. Thank you so much.

Do you mind if I ask some follow-up questions?

  1. To ensure Google never gets confused about which of my domains is the Canonical, I would just need to be really consistent about always using the *https://www.*goodgoodgood.co version of the link in the Canonical tag on each page, right? Anything else I should be mindful of so I don’t dilute across multiple domains we own?

  2. For our CMS articles pages, I have a code that says, “If there’s a URL in the Canonical collection field… then use that as the Canonical URL. If not, leave blank.” Do you know how I could write that as “… If not, then make the URL of the current page the Canonical URL”? If I could figure that out, I could put that in the Custom Code section for the whole site — and it would solve all of my problems without room for mistake.

If it helps, here’s the current code:

<script>
const curl = "CANONICAL URL"
if (curl != "") {
  link=document.createElement('link');
  link.href='{{wf {&quot;path&quot;:&quot;canonical-url&quot;,&quot;type&quot;:&quot;Link&quot;\} }}';
  link.rel='canonical';
  document.getElementsByTagName('head')[0].appendChild(link);
}
</script>

Thank you again for your help!

Hi @brandenh,

Thanks for your reply and good questions.

I would just need to be really consistent about always using the https://www.goodgoodgood.co version of the link in the Canonical tag on each page, right? Anything else I should be mindful of so I don’t dilute across multiple domains we own?

I would only use one canonical url on each page, so in that sense, it does help to make sure you are using the correct urls, I would always use the same form of the domain like https://www.mydomain.com in the canonical tags.

Typically this is the same as the Default domain set for your site project on the hosting tab of project settings.

On the custom code, here is some update you can make to the code to check if the url is not blank and if not blank then use value from CMS, or if blank, then use the page slug dynamic field combined with a path to the articles collection to create the current page url:

Webflow - Good Good Good 2022-01-13 at 5.17.59 PM

You might give that a try, republish after changing the custom code and test with and without value in the canonical url field in the collection.

I hope this helps

@cyberdave, thank you so much for your help.

I believe I implemented this based on your recommendations, but unfortunately it looks like there’s still something wrong.

Here’s a breakdown:

(Note: I’ve temporarily turned the Global Canonical Tag back on in Webflow’s settings, but you should still be able to see that the non-Good Good Good canonical tags aren’t seeming to work)

Here’s a URL that should have the Canonical tag pointing to a different website (because we added a URL to the Canonical Link section of the CMS): Texas Faith Communities Are Helping Their Congregations Get Vaccinated at Church

When I check the canonical using this tool (Canonical Tag Test | SEO Site Checkup) there should be a conflict, showing the Canonical from the Global Canonical Tag in settings AND the Canonical from the CMS and new code. But unfortunately it’s not showing the Canonical from the CMS.

Any ideas on what might be going wrong — or where the problem in the code may be?

Thank you SO much for your help.

Oh, and in case it’s helpful for comparison:
Here’s a URL that should be pointing to itself as Canonical: Best Inspirational Dolly Parton Quotes About Life & Love

Thank you again!

I’ve tried out a few new things and can’t seem to get this code to show a Canonical URL from the CMS. If anyone can see what’s wrong with my code, I’d appreciate it.

Screen Shot 2022-01-22 at 10.36.57 AM
(Update: Replaced the screenshot because I caught an error. But it’s still not validating.)

Alright — I think I got it figured out.

Wanted to share for anyone who stumbles across this thread in the future!

Screen Shot 2022-01-24 at 7.02.46 AM

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.