Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php (revision 18671)
+++ wp-includes/link-template.php (working copy)
@@ -2355,21 +2355,62 @@ function get_edit_profile_url( $user, $scheme = 'admin' ) {
}
/**
- * Output rel=canonical for singular queries
+ * Output rel=canonical
*
* @package WordPress
* @since 2.9.0
*/
function rel_canonical() {
- if ( !is_singular() )
- return;
+ $link = false;
+ $pagination_type = false;
+
+ if ( is_singular() ) {
+ $link = get_permalink( get_queried_object() );
+ if ( get_query_var('page') > 1 ) {
+ if ( !$wp_rewrite->using_permalinks() ) {
+ $link = add_query_arg( 'page', get_query_var('page'), $link );
+ } else {
+ $link = user_trailingslashit( trailingslashit( $link ) . get_query_var( 'page' ), 'single_paged');
+ }
+ }
+ } else {
+ if ( is_front_page() ) {
+ $link = home_url( '/' );
+ } else if ( is_home() && "page" == get_option('show_on_front') ) {
+ $link = get_permalink( get_option( 'page_for_posts' ) );
+ } else if ( is_tax() || is_tag() || is_category() ) {
+ $term = get_queried_object();
+ $link = get_term_link( $term, $term->taxonomy );
+ } else if ( is_post_type_archive() ) {
+ $link = get_post_type_archive_link( get_post_type() );
+ } else if ( is_author() ) {
+ $link = get_author_posts_url( get_query_var('author') );
+ } else if ( is_archive() ) {
+ if ( is_date() ) {
+ if ( is_day() ) {
+ $link = get_day_link( get_query_var('year'), get_query_var('monthnum'), get_query_var('day') );
+ } else if ( is_month() ) {
+ $link = get_month_link( get_query_var('year'), get_query_var('monthnum') );
+ } else if ( is_year() ) {
+ $link = get_year_link( get_query_var('year') );
+ }
+ }
+ }
+
+ if ( $link && get_query_var( 'paged' ) > 1 ) {
+ global $wp_rewrite;
+ if ( !$wp_rewrite->using_permalinks() ) {
+ $link = add_query_arg( 'paged', get_query_var( 'paged' ), $link );
+ } else {
+ $link = user_trailingslashit( trailingslashit( $link ) . trailingslashit( $wp_rewrite->pagination_base ) . get_query_var( 'paged' ), 'paged' );
+ }
+ }
+ }
- global $wp_the_query;
- if ( !$id = $wp_the_query->get_queried_object_id() )
- return;
+ $link = apply_filters( 'rel_canonical', $link );
- $link = get_permalink( $id );
- echo "\n";
+ if ( $link )
+ echo "\n";
}
/**
@@ -2485,4 +2526,4 @@ function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) {
}
}
-?>
+?>
\ No newline at end of file