Duplicate content is always an issue in search engines, especially in the context of content management systems and blogging applications. Therefore, they decided together (Google, Yahoo and Microsoft) for a notice using the link tag.
In essence, provides the tag with the rel attribute canonical only a reference to the preferred URL. Once again a new discussion started in the WP Hacker List about this new possibility, which I can not understand. WordPress offers plenty of opportunities so that this form is not necessary to be included in the core, there is sufficiently different and more important topics and the content of a theme should be broadly still lie with the developer. I will show you in this post a simple and quick way to integrate the attribute.
Without getting in details and to enter the SEO world, I will pass on some links, which sufficiently explained the issue with enough background on this topic. Useful and concise is the article „Specify your canonical“ and Yoast provides information and a Plugin on this topic.
As always, you can use various Plugins or expand your theme for indication for the search engines. The second possibility is shown below in my favorite code.
'; ?>
The above code has to be in the head
of the theme, usually in the header.php
of the theme and you’re done. From now, every single page and post has the notice on the preferred URL. For the query of page or post takes care the Conditional Tag is_singular()
since WordPress version 1.5 in the core.
Comments
13 responses to “rel=”canonical”-URL for WordPress Theme”
Good tip on the canonical urls. I’ll have to use that in the future.
However, although
is_singular()
might work, the proper conditional tag isis_single()
: http://codex.wordpress.org/Conditional_Tags#A_Single_Post_PageMatt,
is_singular()
applies the rel=”canonical”-link to single post view AND pages.Thanks for that; it looks like a worthwhile addition to the header file. Much appreciated. 🙂
It’s not that Simple
If my URL is already canonical i’m going to say this page’s canonical url is this page and that’s a bad use of it.
If the site’s url is p=387 and you want to say the canonical url is /post-about-something/ the code you shared isn’t enought.
I agree with @Mário Andrade ,but it can be use between page/ and page/1/ if you don’t want to show the url page/1/ in google or any other Search Engine.
I wrote a post about this topic a while ago – Avoid Duplicate Content – Use Canonical URL in WordPress
Check out Canonicals WordPress Plugin.
Very nice
Nice indeed. One problem for me though, it does not seem to place the rel=”canonical” link to the home page. Any work-around or is this not a concern?
Nice – very very useful for SEO purposes – would recomment people follow this =)
I am using this wp plug in www. yoast.com/ wordpress/ canonical/ for canonical urls
i’ve read that wordPress 2.9 adds a new tag to the page header which specifies the canonical path to the actual content. do you know how i can enable this feature?
Stjepan, here is a article https://wpengineer.com/support-in-wordpress-for-relcanonical/