Make WordPress Core

Ticket #10115: rel_canonical.txt

File rel_canonical.txt, 366 bytes (added by ryan, 16 years ago)

Untested snippet that adds rel=canonical for is_singular() pages.

Line 
1function rel_canonical() {
2        if ( !is_singular() )
3                return;
4
5        global $wp_the_query;
6        if ( !$wp_the_query->get_queried_object_id() )
7                return;
8
9        $link = get_permalink( $wp_the_query->get_queried_object_id() );
10        echo "<link rel='canonical' href='$link' />\n";
11}
12
13add_action( 'wp_head', 'rel_canonical' );