The What, Why, and How of Canonical Tags & URLs
“This is canon!”
You may have heard this phrase to describe a creative work that remains true to an original work or a fictional universe.
If you are familiar with Canon, you are well on your way to understanding canonicalization and how it affects web pages.
Here let’s examine what canonicalization is, why it’s important to SEO, and how to add the tag to your own website.
What is Canonization?
Canonization declares an original or preferred website, which allows duplicate pages to be consolidated for crawling.
Without naming a canonical URL, web crawlers could crawl and index multiple versions of your website. Google states that non-canonical pages are crawled less frequently to reduce the crawling load on your website.
The less frequent crawling of low-quality, duplicate pages means that more important pages can be prioritized for crawling instead.
Okay, but why should we have duplicate content on purpose? Well … have you ever published your content on your website and also on Medium? Or maybe after the guest post, you will also place a version of the blog post on your website.
To do this, you should reference the original version as a canonical URL. Canonical URLs can point to different domains – that is, the canonical URL can be on another website.
Even if you don’t actively create duplicate pages for cross-channel advertising, there will of course be duplications due to the different parts of a web address. Does your website use a secure protocol like HTTPS? Then you may have an HTTP and HTTPS version of your website.
The same is true of www versus non-www. Does your website use trailing slashes or not? If your website doesn’t always redirect to the preferred version of your page (safe or not, www or not, and trailing slash or not), duplication may occur.
Even if you force the preferred version through a redirect, query parameters that are used to track visits or filter views on a page may look like separate URLs to crawlers. Declaring a canonical URL tells web crawlers to ignore query parameters or other versions of the URL.
What is a canonical url?
The external resource element defines relationships between the current page and other resources. A “rel” attribute is used in theTag used to indicate the type of relationship. Some common link types are “prev” and “next” for pagination, “stylesheet” and of course “canonical”.
TheTag uses the “rel =” noopener “target =” _ blank “href” attribute to set the URL that will serve as the canonical URL for the active page. While these are intended as links to external resources, the canonical URL can be “self-referencing,” meaning it is the exact version of the current page. Using self-referencing canonicals will help reduce unnecessary crawling of non-preferred versions of your page as long as you always use the absolute URL as the “rel =” noopener “target =” _ blank “href” value.
In the Google Search Console, you can use the Check URL tool to understand what Google means by the canonical URL, even if you haven’t set one. Even if you’ve declared a canonical URL, sometimes Google will choose a different URL that will be listed as “Google Selected Canonical”. Because of this, Canonization is not a guarantee that Google will choose your preferred version or that other versions will not be indexed.
How to add a canonical tag
Adding a canonical tag in an HTML document
As mentioned earlier, you can use the item to set your canonical url. Link elements are self-closing tags. The attributes “rel” and “rel =” noopener “target =” _ blank “href” are required.
To add a canonical link to an HTML document, add theElement within the
Elements. Make sure that the “rel” attribute value is set to “canonical”. Remember to include the absolute URL of your preferred web address as the value of the “rel =” noopener “target =” _ blank “href” attribute.Add Canonical Tag in HubSpot Add
In HubSpot, you can set your canonical URL in the individual page or post settings under Advanced Options. Read more about canonical url setting options.
Add a canonical tag in WordPress
Popular WordPress SEO plugins, including Yoast and RankMath, make it easy to set up canonical URLs, especially for multiple pages. If you’re a little more advanced and don’t want to add another plugin, you can also use WordPress hooks to update the canonical URL.
1. Using the get_canonical_url hook.
A filter WordPress hook allows you to change data while WordPress is running. The add_filter () function accepts at least two parameters, a tag and a callback function. The tag would be the hook, in this case get_canonical_url.
The callback function parameter would be the name of a function you created that returns the canonical URL. The callback function could use conditional statements to assign specific contributions. See this Stack Exchange response example.
In the example, the callback function “wpse_302620_canonical_url” uses an if statement to return a new canonical if the post ID passed as an argument to the function matches a specific post. With that in mind, this solution seems like a solution for some posts or post types, but it doesn’t scale well. To apply to multiple sites, using a plugin would probably be the best option.
2. Using the Yoast plugin.
If you’re using Yoast, you can apply canonical URLs to posts, pages, and taxonomies. In the left menu, select the type of content you want to edit, then “edit” each piece of content. Toggle the “Advanced” section in the Yoast SEO metafield. Paste your preferred web address into the Canonical URL field and save. Learn more about Yoast’s canonical URL settings.
3. Using the Rank Math plugin.
While editing your specific page or post, select the “Advanced” tab in Rank Math. Paste your preferred web address into the “Canonical URL” field and save. Learn more about setting canonical URLs in Rank Math.