Last Updated: March 28th, 2018
Canonical Link WordPress Plugin
Canonical Link Firefox Add-on
This add-on will also help you to verify your canonical links are set up correctly.
Canonical Link Script
<link rel="canonical" href="https://<?php echo $_SERVER['HTTP_HOST']; ?><?php echo parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ); ?>" />
This code is ready to go as-is for most websites (PHP support required) without any alteration to it needed. Just paste it directly in between your
<head> ... </head>
tags, which are hopefully located in one universal header file that governs all your pages, or you’ve got a lot of work on your hands.
Adding a canonical link tag to every page of a website, one-by-one, for most, is severely daunting, if not completely impractical or impossible. Especially if you have thousands of pages.
The importance of the canonical link is primarily to clear up duplicate content issues. That is, to help search engines not make the mistake of confusing two different URLs that are actually the same page as two different pages.
The canonical link represents the official URL of a specific piece of content. It also helps to give Google a clean representation and suggestion of what you want your URLs to look like and how you want Google to index and display them in search results.
It’s important to understand that the canonical link is not a rule, but merely a suggestion. Google (and other search engines) can still override your suggestion. It might have been better named Canonical URL Suggestion.
Learn More About the Canonical Link Tag Element
Page vs URL
A page is where the text, pictures, and other content actually display.
The URL (Uniform Resource Locator) is the location of a page. The old days of web design where every page was manually created as a static HTML file are long-gone. Because there are now so many different technologies passing info along through the URLs of websites, is why the need for canonicalization was born. To help search engines understand actual pages vs search and other parameter results because of so many URL variables confusing the bots.
All it is doing is serving up the current page URL as the canonical link?
No. What the dynamic canonical link tag script will do for all these variations:
is suggest the clean and proper:
Again, this script will not just mirror the current URL (unless you’re already on the canonical URL). The list goes on and on how just one page can be shown and reached via different URLs. Search engines can’t fully make certain distinctions (as in can’t make human-based distinctions). They can consider some of those URLs to be different pages. That is why canonicalization was created, to help clear up duplicate page issues because of the many possible URL variations.
But, I have https://www.example.com/portfolio/page-1/ and https://www.example.com/portfolio/page-2/ that are virtually the same page and page 2 will just canonicalize as itself? I want all portfolio pages to canonicalize as just https://www.example.com/portfolio/
That’s simply not good practice, in my opinion. Page 1 and 2 examples would only make sense being canonicalized if we were talking about: https://www.example.com/portfolio/?id=page-1 and https://www.example.com/portfolio/?id=page-2 or something like that.
Otherwise, what that would be suggesting would almost certainly be overruled by Google’s judgment. It’s not good practice to completely canonicalize one page as another (unless crediting an original article source for example — if posting the same content on multiple sites). Say you had a projects page: https://website.com/projects/ and subsequent pages listing projects alphabetically: https://website.com/projects/a/, https://website.com/projects/b/, etc.
Those are distinctly separate pages that should not canonicalize to the main page https://website.com/projects/. That’s not the purpose of canonicalization. If it’s a page, it’s a page, bottom line. The point is to canonicalize to the cleanest, proper default URL for that page, not an entirely different page. The use of
would probably be more appropriate here.
However, if we were talking about sections like: https://website.com/projects/#a, https://website.com/projects/#b, etc., then yes, they should canonicalize as just: https://website.com/projects/.
It’s your job as a webmaster to not create two fully different pages that are exactly or basically duplicates. Remember the canonical link is not a rule and does not necessarily enforce anything. It is only a suggestion.
You, as a webmaster, should also never rely solely on the canonical link. You need to be doing everything else right too. You need a good .htaccess file with appropriate redirects and your own internal link structure should be consistent and show URLs how you want them to be shown.
For the case of actually wanting or needing to have two or more exact (or close to) duplicate pages and you don’t want them all indexed, the proper method would actually be to use the following tag:
<meta name="robots" content="noindex" />
Hopefully, that clears up some of the misconceptions about the canonical link element. It is not a lone wolf, it must work together with a pack of SEO techniques.
A Good .htaccess File is Also Advisable
Besides keeping your internal link structure and navigation clean and consistent from the get-go, you can further ensure that people reach and link to clean, well-structured URLs, with an .htaccess file. You can find an example of one here.
How to have SEO-Friendly URLs in WordPress
- From your WordPress Admin, navigate to: Settings > Permalinks
- Under “Common settings,” select: “Post name”
- Click “Save Changes” and you’re done
Important Note for WordPress Users
WordPress core has implemented the canonical link automatically by default since version 2.9. And if that wasn’t the case, there are still plenty of SEO plugins (I recommend All in One SEO Pack) that get the job done very well. With those two points in mind, a lot of the advice and tools above are probably obsolete for most people. However, if you do still find any of my methods useful, let me know.