How to fix ‘Non-canonical URL’ error from categories in Squarespace

In the Squarespace's built-in blog you can add categories for your blogs. This is usually recommended as its easier for users to find what they are looking for.

However if you’re using Google Search Console, or other SEO auditing tools, you may come across the error, ‘Non-canonical URL’, on your blog category pages, eg: blog/category-name.

This is because Google can see that content on this page is very similar to other pages on your website. (This makes sense considering the category pages are the standard blog pages, with a filter applied). But of course, we don’t want to be marked down in our SEO by Google!

To fix this issue, we want to add a Canonical link in the head of the page only for the category pages. This will let Google know the original origin of the content on the page.

To achieve this, we want to add some code to the HEADER section:

  1. Open the Developer tools panel

  2. Click Code Injection.

  3. Add the below code in the header section

  4. Update the canonical Link to be your website domain

 
<script>
  const collections = [
    {categoryLink: '/blog/category/', canonicalLink: 'https://your-domain/blog/'}
  ]

  collections.forEach(({categoryLink, canonicalLink})=> {
    if(window.location.pathname.includes(categoryLink)) {
      const squarespaceSetCanonical = document.querySelector("link[rel='canonical']")
      if(squarespaceSetCanonical) {
          squarespaceSetCanonical.remove()
      }
      const linkTag = document.createElement('link');
      linkTag.setAttribute('rel', 'canonical');
      linkTag.href = canonicalLink
      document.head.appendChild(linkTag)
    }
  })
</script>
 

I have put the collections into an array, the idea behind this is you can easily add more if you have multiple collections with the same issue, see below for an example:

  const collections = [
    {categoryLink: '/blog/category/', canonicalLink: 'https://your-domain/blog/'},
    {categoryLink: '/testimonals/category/', canonicalLink: 'https://your-domain/testimonals/'}
  ]
 

If you have any questions or issues, please feel free to contact us. Hope this helps!

Previous
Previous

Squarespace Template Must Haves for Consultants

Next
Next

The Power of Human Psychology in Web Design: 5 Homepage Hacks That'll Blow Your Mind!