rel=canonical for singular pages. see #10115

git-svn-id: http://svn.automattic.com/wordpress/trunk@11777 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-08-05 16:43:51 +00:00
parent e15de47ed7
commit 04d3d11213
2 changed files with 19 additions and 0 deletions

View File

@ -178,6 +178,7 @@ add_action('wp_head', 'noindex', 1);
add_action('wp_head', 'wp_print_styles', 8);
add_action('wp_head', 'wp_print_head_scripts', 9);
add_action('wp_head', 'wp_generator');
add_action('wp_head', 'rel_canonical');
add_action('wp_footer', 'wp_print_footer_scripts');
if(!defined('DOING_CRON'))
add_action('sanitize_comment_cookies', 'wp_cron');

View File

@ -1806,4 +1806,22 @@ function plugins_url($path = '', $plugin = '') {
return apply_filters('plugins_url', $url, $path, $plugin);
}
/**
* Output rel=canonical for singular queries
*
* @package WordPress
* @since 2.9.0
*/
function rel_canonical() {
if ( !is_singular() )
return;
global $wp_the_query;
if ( !$id = $wp_the_query->get_queried_object_id() )
return;
$link = get_permalink( $id );
echo "<link rel='canonical' href='$link' />\n";
}
?>