Ticket #18660: link-template.php.2.diff
File link-template.php.2.diff, 1.3 KB (added by , 14 years ago) |
---|
-
wp-includes/link-template.php
2355 2355 } 2356 2356 2357 2357 /** 2358 * Output rel=canonical for singular queries2358 * Output rel=canonical for home, singular, author archives, and taxonomy archives. 2359 2359 * 2360 2360 * @package WordPress 2361 2361 * @since 2.9.0 2362 2362 */ 2363 2363 function rel_canonical() { 2364 if ( !is_singular() ) 2365 return; 2364 2365 global $wp_query; 2366 2367 /** Get the object ID */ 2368 $id = $wp_query->get_queried_object_id(); 2366 2369 2367 global $wp_the_query; 2368 if ( !$id = $wp_the_query->get_queried_object_id() ) 2370 $canonical = ''; 2371 2372 if ( is_front_page() ) { 2373 $canonical = trailingslashit( home_url() ); 2374 } 2375 2376 if ( is_singular() ) { 2377 $canonical = get_permalink( absint( $id ) ); 2378 } 2379 2380 if ( is_category() || is_tag() || is_tax() ) { 2381 $canonical = get_term_link( absint( $id ), $wp_query->queried_object->taxonomy ); 2382 } 2383 2384 if ( is_author() ) { 2385 $canonical = get_author_posts_url( absint( $id ) ); 2386 } 2387 2388 $canonical = apply_filters( 'rel_canonical', $canonical, $id ); 2389 2390 /** If empty, return nothing */ 2391 if ( ! $canonical ) 2369 2392 return; 2370 2393 2371 $link = get_permalink( $id);2372 echo "<link rel='canonical' href='$link' />\n"; 2394 printf( '<link rel="canonical" href="%s" />' . "\n", esc_url( $canonical ) ); 2395 2373 2396 } 2374 2397 2375 2398 /**