Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 18667)
+++ wp-includes/link-template.php	(working copy)
@@ -2355,21 +2355,50 @@
 }
 
 /**
- * Output rel=canonical for singular queries
+ * Output rel=canonical
  *
  * @package WordPress
  * @since 2.9.0
 */
 function rel_canonical() {
-	if ( !is_singular() )
-		return;
+	$link = false;
+	
+	if ( is_singular() ) {
+		$link = get_permalink( get_queried_object() );
+		if ( $page = get_query_var('page') && 1 != $page )
+			$link = user_trailingslashit( trailingslashit( $link ) . get_query_var( 'page' ) );
+	} 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_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;
+			$link = user_trailingslashit( trailingslashit( $link ) . trailingslashit( $wp_rewrite->pagination_base ) . get_query_var('paged') );
+		}
+	}
 
-	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";
+	$link = apply_filters( 'rel_canonical', $link );
+	
+	if ( $link )
+		echo "<link rel='canonical' href='" . esc_attr( $link ) . "' />\n";
 }
 
 /**
@@ -2485,4 +2514,4 @@
 	}
 }
 
-?>
+?>
\ No newline at end of file
