rel=”canonical”-URL for WordPress Theme

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.


Posted

in

by

Comments

13 responses to “rel=”canonical”-URL for WordPress Theme”

  1. Matt Wiebe Avatar

    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 is is_single(): http://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page

  2. Michael Avatar

    Matt, is_singular() applies the rel=”canonical”-link to single post view AND pages.

  3. ...paul Avatar

    Thanks for that; it looks like a worthwhile addition to the header file. Much appreciated. 🙂

  4. Mário Andrade Avatar

    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.

  5. Leeiio Avatar

    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.

  6. Atw Avatar
    Atw

    Very nice

  7. iceflatline Avatar

    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?

  8. Corporate Graphic Design Avatar

    Nice – very very useful for SEO purposes – would recomment people follow this =)

  9. Elyot Avatar

    I am using this wp plug in www. yoast.com/ wordpress/ canonical/ for canonical urls

  10. Stjepan Tafra Avatar

    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?