Canonical Link WordPress Plugin
Download Now | Find on WordPress with Instructions | Help Forum
Canonical Link Script
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 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, this can also help to clear up duplicate page issues.
It’s important to understand that the canonical link is not a rule, but merely a suggestion, Google (and other search engines) can still overrule your suggestion. It might have been better named Canonical URL Suggestion.
So without further wait, this code is ready to go as is for any website without any alteration to it needed, just paste it directly in between your:
<head> ... </head>
tags which are hopefully located in one dynamic/universal header file that governs all your pages or you’ve got a lot of work on your hands
:
For a live demo, this very page is using the code, reference the little “C” in the URL bar in your browser. (in Firefox)
Other Plugins to Assist in Canonicalization
Homepage Canonical Link – Adds a canonical link to your blog’s home page, which the current WordPress does not do. – Thanks Joost Schuur
Remove Default Canonical Links – Disables WordPress’ default generation of canonical links. Useful if you’re generating your canonical links through other means. – Thanks Joost Schuur
WP .htaccess Control – Manage your .htaccess file.
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 URL’s with an .htaccess file. You can find an example of one here and a dynamic one here.
Here’s a WordPress plugin to help with .htaccess management.
How to have SEO-Friendly URLs in WordPress
- From your WordPress Admin, navigate to: Settings > Permalinks
- Under “Common settings“, select “Custom Structure” and paste in: /%postname%/
- Click “Save Changes” and you’re done
Learn More About the Canonical Link Tag Element
First, pay visit to and learn from a true authority on the subject:
http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=139394
Common Misunderstanding with My Script / Plugin:
All it is doing is serving up the current page URL as the canonical link?
Untrue: What the dynamic canonical link tag script will do for all these variations:
http://website.com/ | http://www.website.com/ | http://website.com/index.php | http://www.website.com/index.php | http://website.com/#section1.2 | http://www.website.com/#section1.2 | http://website.com/?=source=twitter+is+cool&id=2654683 | http://www.website.com/?=source=twitter+is+cool&id=2654683
The list goes on and on how just one page can be shown and reached, but this script will NOT just mirror the current URL, what it will do for all these variations (and there are a ton more possible variations) is suggest the clean and proper:
http://www.website.com/
Search engines can’t fully make certain distinctions (as in can’t make human based distinctions), they can consider some of those pages to be different, that is how it aims to clear up duplicate page issues.
But, I have http://www.example.com/portfolio/page-1/ and http://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 http://www.example.com/portfolio/page-1/
Page 1 and 2 examples would only make sense if we were talking about:
http://www.example.com/portfolio/?id=page-1
and
http://www.example.com/portfolio/?id=page-2
or something like that.
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. 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 never rely on canonical link, you need to be doing everything else right too. You need a good .htaccess file, your own internal link structure should be consistent and show URL’s how you want them to be shown.
And for the case of the page 2 issue, if you really want to show duplicate or close to duplicate pages and don’t want them indexed the proper method would actually be to use the:
<meta name="robots" content="noindex" /> tag.
So 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.
Not Happy with the Plugin? | Let’s Make it Better
What does the plugin not do right? | What would you like to see the plugin do?
Let’s get the suggestions and questions going in the forum:
http://www.bryanhadaway.com/forum/canonical-link/
Thanks, Bryan











Hi Bryan,
I have installed this canonical link, but it doesnt appear ‘C” on my web.. can you help to take a look what’s wrong with the installation?
Hi Benny, I’ve checked http://bennykusman.com/ for you and you’ll be happy to hear that it is working perfectly.
The “C” is a feature native to Firefox which I recommend using anyways:
http://www.mozilla.com/?from=sfx&uid=266924&t=318
Thanks, Bryan
I had to deactivate this plugin because, I found that the very purpose for which this plugin was used got defeted, as it simply echoed the URL as canonical. For example
If the canonical URL is: “http://abcanylink.com/anything/”
and the link in the URL is: “http://abcanylink.com/anything/?utm_source=twitterfeed&utm_medium=twitter”
then using this plugin, the canonical URL shown in the header is: “http://abcanylink.com/anything/?utm_source=twitterfeed&utm_medium=twitter”
Hi Anup,
You can manually enter the code found above into the head section of your header.php file and it should work perfectly for you. Working on an update for the plugin.
Thanks, Bryan
Update: Canonical Link 1.1 is now available:
Download Now | Find on WordPress with Instructions
Thanks, Bryan
First of all, I don’t understand why you at a first place needed to create this functionality since it is included in WordPress core since version 2.9.
Second, this is definitely not a right way to make canonical URL what you are using in code.
So I do not recommend use of this plugin.
Ya, i had the same idea. Im not too sure what is the purpose though it looks good at the introduction… i already deactivate it…. probably Bryan should elaborate the purpose for this plugin more.
Well, I think there’s no argument there, if you don’t care about or want canonical links in the first place, there’s no reason to look into this plugin and of course it wouldn’t be useful to you.
You’re correct, in the newest versions of WordPress, canonical links are already in place, but this plugin covers WordPress versions as early as 1.2 which aren’t covered. Also, it’s worth mentioning that the WordPress native canonical link itself is flawed. It fails to even properly canonicalize home pages, this might be fixed in WordPress 3.0.
There’s no doubt that entering canonical links manually page by page would be the most “accurate” and ideal way to go about it.
But, as we know… if you have hundreds of pages that is definitely not practical. To elaborate more, the purpose of canonicalizing a link is to serve up to search engines (Google, Yahoo, Bing etc.) a cleaner more attractive, seo-friendly and user-friendly version of URLs.
Another important factor to consider is duplicate content; the same page, could be indexed several times in different formats and Google’s crawler could fail to understand that’s just one page, because the same content can be reached with so many variables;
“http://www.website.com/”, “http://website.com/”, “http://www.website.com/index.php”, “http://website.com/index.php”, “http://www.website.com/#section1.2″, “http://www.website.com/?=section1.2&yes&on”
It will suggest: “http://www.website.com/” for that page
It strips off hash (#) and query (?) tags. It’s important to keep in mind that a canonical link does not actually change the browser URL or alter the page in any way, it only serves a suggestion for a cleaner URL to Google.
The Bottom Line:
My canonical link code/plugin is the best free, dynamic and hands-free way to implement canonical links into large-scale websites and WordPress blogs that I’m aware of. It can not hurt your website, it can only help it.
I emphasize the words dynamic and hands-free because there is another canonical link plugin to choose from: http://wordpress.org/extend/plugins/canonical/ that might be better suited for you if you’re willing to set every single page and post canonical link by hand. It’s worth noting that it only works with WordPress 2.9+ and that it only applies to pages and posts and not the rest of your WordPress website.
The best full on method to get clean URL structures is a good combination of setting your Permalinks to Custom Structure: /%postname%/, using a good .htaccess file and canonicalizing links.
So if you don’t like it or you don’t think it works the way you think it should don’t just say that and leave it at that, that helps nobody. Get specific; What does the plugin not do right? What would you like to see the plugin do?
Let’s get the suggestions and questions going in the forum:
http://www.bryanhadaway.com/forum/canonical-link/
Thanks, Bryan
Is it so, where is that in the admin panel? Or does it get generated ? I dont find it in the headers though.
@Anup
It should be generated in the default theme automatically, I’m not entirely sure.
I think it might only present itself on a “needed” basis. But, I just tested my blank WordPress 2.9.2 w/Default Template setup that I use for testing and I tried adding #test and ?test to URLs and I couldn’t get it to prompt a canonical link.
Which brings up another scenario of when a canonical link plugin could be useful… because even with the newest version of WordPress, it might be theme dependent if it’ll work or not because it’s served up in header.php.
I don’t think it does anything different than the plugin anyways, so I’d be interested to hear specific examples of problems. I did already update the plugin based on your suggestion Anup, so I am listening.
Thanks, Bryan
@Bryan. The point really is what exactly is and most likely to be considered a canonical link?
And I give here an example from my website:
Say the link: “http://indiapoint.net/ca/2006/02/27/articleship/”
Now the above post has various comments to it. So, for smooth loading, I have put around ten commnet threads to be shown.on each page.
So, there are different pages that gets generated viz
“http://indiapoint.net/ca/2006/02/27/articleship/comment-page-5/”
“http://indiapoint.net/ca/2006/02/27/articleship/comment-page-4/”
etc.
Now, if there is only one canonical link, the above pages would have the canonical link of the original post viz. “http://indiapoint.net/ca/2006/02/27/articleship/” So that would defeat the purpose.
However at the same time, there can be search links like “http://indiapoint.net/?s=training” So what would be the canonical link for such links?
At the same time, I would not like that search-engines pick up from somewhere link like “http://abcanylink.com/anything/?utm_source=twitterfeed&utm_medium=twitter” and count it as a link.
thanks
I have written a reply, but it seems that your spam protection is working overtime.
It’s because of all the URL examples we’re using that’s sparking the spam filter, but I approved your comment and my response is above.
Thanks, Bryan
Here’s how the plugin will handle all these pages:
“http://indiapoint.net/ca/2006/02/27/articleship/” (no suggestion needed, no suggestion will occur)
“http://indiapoint.net/ca/2006/02/27/articleship/comment-page-5/” (no suggestion needed, no suggestion will occur)
“http://indiapoint.net/ca/2006/02/27/articleship/comment-page-4/” (no suggestion needed, no suggestion will occur)
Each of these pages will be respectively left alone, no suggestion will be needed. They will all be indexed the way they are as they should. You should want comment pages to be indexed because there are often rich info filled comments that can bring in visitors.
“http://indiapoint.net/?s=training” canonicalized as “http://indiapoint.net/”
This is good, it’s not really good practice or appropriate to index search pages anyways as this annoys most, to go from search results to more search results.
“http://abcanylink.com/anything/?utm_source=twitterfeed&utm_medium=twitter” canonicalized as “http://abcanylink.com/anything/” respectively
Canonical links again are mere suggestions for Google. It’s an added technique, but not the only technique to consider, a good .htaccess file and seo-friendly permalinks are also advised.
If ever you didn’t want a page to be indexed, the proper method would be to use:
<meta name="robots" content="noindex" />in the head section. Here’s a WordPress plugin that could handle such a task:
http://wordpress.org/extend/plugins/ultimate-noindex-nofollow-tool/
I have to think about making the plugin universal or basic to cover the average need. There may certainly be other needs, this plugin could be customized very easily to someone’s specific need.
For example, perhaps some pages; you might want to block from being canonicalized altogether or changing how URL’s are canonicalized for specific pages. Right now, the plugin is at a pretty fair baseline of what should be expected from a canonicalized link.
All and all for people that want to canonicalize hundreds or even thousands of pages dynamically without doing it manually themselves or paying someone, it’s pretty decent. It might not get every page spot on of how you would do it manually, but it’ll certainly do a good job with most and better your site.
Again, it’s completely free an open source, if someone has a specific request for their own custom setup I could try and help, if I couldn’t I’m sure they could hire a programmer for 1 – 2 hours that could refine it to their specific websites needs.
Right now, I’m thinking it’s canonicalizing pretty good in most cases no differently than how someone would manually do it, so the only thing I’m thinking is that there might be pages that people just don’t want to canonicalize at all for whatever reason, so I’ll look more into that, shouldn’t be too difficult.
I’m also thinking of an alternate that might handle product pages a little differently, but I need more feedback first, lots of feedback. GOOD feedback like you’ve provided Anup and I appreciate that. When people just say they don’t like it or it doesn’t work, that’s pretty vague and subjective and doesn’t do anything in way of helping.
I started a subforum here for suggestions: http://www.bryanhadaway.com/forum/canonical-link/suggestions-for-improvement
Thanks, Bryan
I have re-implemented your plugin (perhaps it is an updated one downloaded from your site). Now it works really well – and what I had written previously regarding its deficiency no longer exists. thanks.
Hi Anup, that is wonderful to hear. Yes, you’re probably using the updated ver 1.2. You’ve been very helpful, if you have any other requests for features or suggestions please always feel welcome to share your feedback.
Thanks, Bryan
Bryan, I’d recommend some clarification in your plugin description for WordPress 3.0 users. Aside from canonical links not being used on the blog front page, you mentioned something about WP’s own implementation having flaws. I too noticed the utm querystring junk to my front page and wasn’t sure if it was worth installing a plugin for just the front page, when I knew WordPress 3.0 already managed it for multiple pages.
If however, 3.0 has other canonical URL bugs beyond not covering the front page, then it seems like more of a clear cut choice to use the plugin.
Of course, going the plugin route is a safe way to keep custom changes out of your template files and also means it’s a simpler choice for people not comfortable editing them.
The site in question where I implemented it is http://iosdevgoodies.joostschuur.com BTW.
The canonical link has definitely been improved in WordPress 3.0. However, I don’t think it covers every single page like the plugin does. Instead is only set to cover pages that might require it out-of-the-box like post pages that have #comments sections and so forth.
I think this plugin is just about perfect for 90% of WordPress users. But for those that have used WordPress for CMS for a serious store/shopping cart e-commerce website with thousands of products, they should definitely have a professional programmer alter the PHP of the plugin and create a custom .htaccess file, but websites of that scale are probably on top of it anyways.
I don’t think I ever want to create a version of the plugin that required any settings adjustments from the admin. I just want it to be activate and done. For those who have very specific custom needs I want to get problems and solutions going in the forum:
http://www.bryanhadaway.com/forum/canonical-link/
Thanks, Bryan
I wanted to post this in the suggestion forum, but was not able to log in there. It said there was an account with email address, but the password reminder option gave me an error.
My suggestion was related to duplicate canonical link entries that your plugin now generates, since WordPress does its own. From another blog post, someone recommended adding remove_action( ‘wp_head’, ‘rel_canonical’ ); to your theme’s function.php to unregister WP’s default canonical link. That seemed sensible, but didn’t seem to work for me in the TwentyTen theme. You may want to consider integrating this approach into your own plugin when you get it working.
I just reset your password, check your email. I think with 3.0 the two canonical link codes shouldn’t play together, so if you decide to remove the default canonical link element from WordPress, for earlier versions I suspect your method would work, but for 3.0+:
http://sageblogger.com/tip-for-datafeedr-users-removing-rel-cannonical-why-and-how/
Let us know if this solution works if anyone’s tried it.
Thanks, Bryan
That post suggests modifying core WordPress files that get overwritten when you do your next upgrade, which is why putting it in the theme files made more sense to me.
In the end, I went with a feature of the HeadSpace plugin, which I’m already been using, added a ‘raw data’ module and then in the home page settings for that plugin added ” for the raw data field. This at least covers my original intent, getting my front page ‘fixed’.
That said, for 3.0 users there’s still the need to do this in a nice and simple way, and for some people HeadSpace might be a lot of overhead. It really comes down to whether duplicate canonical links are going to harm you down the road.
Quickly disabling WordPress’ own canonical links programmatically still leaves it a lean and mean plugin with no visible user configuration.
Yeah, I definitely DO NOT recommend having duplicate canonical links. I’m sure Google would just go to the first one, but I don’t know what unforeseen problems this could have either.
So, I would definitely recommend choosing either the WordPress default canonical solution or a canonical plugin. I don’t believe WordPress versions prior to 2.9 even have a default canonical link element, so that isn’t a worry. For newer versions, I believe there is a plugin to remove the default canonical and then it wouldn’t get in the way of updating.
I know there were some, but I’m not seeing any good ones, I may consider developing a “Remove Canonical” plugin.
It’s worth noting too that I just noticed another plugin, that can be very useful to assist canonical links:
http://wordpress.org/extend/plugins/wp-htaccess-control/
Thanks, Bryan
A separate plugin to remove canonical links would be a great idea. That way, people could use it regardless of what other solution to add canonical URLs to their pages they’re implementing, and it would be theme independent. It sounds like the easiest plugin in the world to write too, just a step up from Hello Dolly, since it just comes down to a single remove_action call. I might even try my hand at it, as a way to get into plugin development. If you’re not going to release one, I can do that.
I noticed that in my instructions above, the actual appropriate canonical link tag was stripped out because the comments area interpreted it as HTML. So where I said ‘and then in the home page settings for that plugin added ”’, don’t add a blank string of course, add the correct canonical link tag for your home page.
Yeah, I’ve even written an article that will help jumpstart you on building it if you decide to:
http://www.bryanhadaway.com/getting-started-with-your-first-wordpress-plugin/
If you could… let me know by tonight or I’ll go ahead and make it tomorrow.
Thanks, Bryan
Great! But if you have for example “http://www.website.com/coding/”, it can’t provide “http://www.website.com/coding” and vice-versa, when “coding” is a file (for example coding.html or coding.php renamed to coding via htaccess).
Actually, that’s a good thing. You don’t want to “lie” to Google. If this is really how the page lands; “http://www.website.com/coding”, then that is how it should canonicalize, because if you set the canonical to: “http://www.website.com/coding/” it will always be a redirect from Google although Google might ignore the suggestion altogether anyways.
The main structure of a URL that the users sees with the hash # and query ? tags cut out of course should be how the page canonicalizes.
It can and does create the right canonical link for your scenario. I’ve incorporated the canonical link code I’ve written on this page into a free website template I offer here:
http://www.freewebplate.org/
where I am actually practicing stripping off .php for “prettier” URL’s in .htaccess, see the demo:
http://www.freewebplate.org/demo/contact
And you’ll see that it respects the removal of .php and the trailing slash /.
Basically, what my code does is strips out hash # and query ? tags which is about 90% the importance of what a canonical link is for.
Other than that it pretty much respects what it sees, so like any good canonical link usage/practice, whether mine or another script, it is also very important to have a good .htaccess file and overall good link structure and consistency in your code.
One important and often overlooked factor in websites is whether or not to be a www or non-www site and then to stick to it strictly.
Let me know if that clears some things up Ismael, or perhaps I misunderstood or maybe you can expand on why what you were suggesting might have a good/useful application.
Thanks, Bryan