2nd Door Of Our Advent Calendar – Support in WordPress for rel=”canonical”

WordPress-Christmas-02
WordPress 2.9 will support the attribute rel and his value canonical, you can also read about it on an older post how to integrate the values and what's about it. Therefore you don't have to paste the HTML explicitly in your theme.

In previous versions of WordPress 2.9, the intergration is easy to do:

<?php if ( is_singular() ) echo '<link rel="canonical" href="' . get_permalink() . '" />'; ?>

Putting it in the header.php of the theme is the easiest way to have the link-tag in the head of your frontend.

Since WordPress 2.9 it won't be necessary because WordPress set with the help of the default filter, see wp-includes/default-filters.php, the link-tag to the hook wp_head.

add_action( 'wp_head', 'rel_canonical' );

Thereby it calls the function rel_canonical(), which simply writes the HTML and passes the link of the article. Alternatively you can disable the filter and you can use it yourself.

remove_action( 'wp_head', 'rel_canonical' ); // to delete in head

Comments are closed.

2 comments

  1. Dam Milward

    Awesome. We've had a couple of requests to integrate this with the WP e-Commerce Plugin for products. Will do!!

One pingback

  1. Wordpress: Canonical verwenden « Braekling.de