Changeset 9319 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
- Timestamp:
- 12/10/2019 11:40:41 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
r9085 r9319 449 449 } 450 450 add_action( 'wp_head', __NAMESPACE__ . '\add_meta_description_for_summary' ); 451 452 /** 453 * Outputs `<link rel="canonical">` tags where appropriate. 454 */ 455 function rel_canonical() { 456 $canonical = false; 457 $queried_object = get_queried_object(); 458 459 if ( is_tax() || is_tag() || is_category() ) { 460 $canonical = get_term_link( $queried_object ); 461 } elseif ( is_post_type_archive() ) { 462 $canonical = get_post_type_archive_link( $queried_object->name ); 463 } 464 465 if ( $canonical && get_query_var( 'paged' ) > 1 ) { 466 $canonical .= 'page/' . (int) get_query_var( 'paged' ) . '/'; 467 } 468 469 if ( $canonical ) { 470 printf( '<link rel="canonical" href="%s">' . "\n", esc_url( $canonical ) ); 471 } 472 } 473 add_action( 'wp_head', __NAMESPACE__ . '\rel_canonical', 9 ); 474
Note: See TracChangeset
for help on using the changeset viewer.