Canonical tag
Webamp / Academy / Canonical tag

Canonical tag

Canonical tags are a vital part of the technical side of search engine optimization (SEO). In this short guide you can learn more about canonical tags - what they are, why you should use them and how to set them up and use them in practice.

Adam Ketelsen
Last updated: 5. dec. 2022

What is a canonical tag?

A canonical tag is a piece of code in the HTML of your website that tells Google which of several identical pages to index and display in search results. 

This is especially relevant on webshops, where the filter function on product pages can have multiple URLs due to the filter function. But it can also be relevant on websites with multiple language layers, if content is reused on multiple URLs, or if a page can be accessed via multiple addresses - typically with and without www. or with and without https://.

The page whose URL you use in your canonical tag will be the canonical URL. Read more about canonical URLs on Google Developers.

Why are canonical tags important?

Duplicate content is a no go in SEOas Google penalises duplicate content with lower rankings. In addition, duplicate content can make it difficult for Google's crawlers to index your website and select the URL you want to rank for a desired keyword.

Let me give you an example from the real web world - more specifically H&M's Danish webshop. Here you will find a category page with dresses. On the page you can sort by colour, size, length and a lot of other parameters. This is potentially a SEO pitfall, because in the eyes of the search engines, it results in a myriad of URLs with duplicate content, as the URL will change with each filtering.

Here is the original URL and the URL after filtering, where I filtered for beige dresses.

What are canonical tags?

And that's where canonical tags come in - and the H&M SEO team knows it well. So they've set up a canonical tag that contains the page's URL without filters - this URL is the canonical URL.

Thus, the canonical URL will always be https://www2.hm.com/da_dk/dame/produkt/kjoler.html, even if the URL changes for each filtering.

Why are canonical tags important?

How to set up canonical tags

Canonical tags skal bo i <head>-sektionen i din hjemmesides HTML – her er det dog vigtigt at understrege, at hver underside på din hjemmeside skal tildeles et canonical tag. I praksis skrives tagget således:

 <link rel=”canonical” href=”https://hjemmeside.dk/eksempel”>

If you have several pages with identical content, insert the tag on the page you want to appear in Google's index and thus in the search results - in other words, the most important of the identical pages.

Most CMSs will automatically insert the page URL into the canonical tag. These are called self-referential canonical tags. But if you have several pages with the same content, you need to insert the URL of the main page into the canonical tag of the alternative pages. This will ensure that Google only crawls your main page. This gives air in the crawl budget and prevents not least confusion from Google.

If you use WordPress, you can use Yoast SEO (which is a SEO plug-in) to specify a canonical URL under 'Advanced'. 

setting up canonical tag in Yoast

På meget store hjemmesider med mange versioner af hver side kan du vælge at automatisere processen, så du ikke behøver at tygge dig igennem opsætningen af canonical tags på 50 forskellige URL’er. Det gør du ved at indsætte følgende generiske kodestykke i hjemmesidens <head>-sektion:

<link rel="canonical" href="{{ canonical_url }}">

This piece of code ensures that the page URL is self-referential - and thus prevents filter functions from messing up your SEO work. This way you can pull off the same trick as the SEO team at H&M.

Get even smarter and increase your online presence

Whether you're a generalist or a marketing specialist, our specialists have put together some great advice for you on our blog.

Learn more at Webamp Academy.