Make WordPress Core

Ticket #22879: 22879.diff

File 22879.diff, 1.2 KB (added by iworks, 9 years ago)
  • wp-includes/link-template.php

     
    32683268 * @global WP_Query $wp_the_query
    32693269*/
    32703270function rel_canonical() {
    3271         if ( !is_singular() )
    3272                 return;
     3271        $link = false;
     3272        if ( is_singular() ) {
     3273                global $wp_the_query;
     3274                if ( !$id = $wp_the_query->get_queried_object_id() )
     3275                        return;
    32733276
    3274         global $wp_the_query;
    3275         if ( !$id = $wp_the_query->get_queried_object_id() )
    3276                 return;
     3277                $link = get_permalink( $id );
    32773278
    3278         $link = get_permalink( $id );
     3279                if ( $page = get_query_var('cpage') )
     3280                        $link = get_comments_pagenum_link( $page );
     3281        } else if ( is_home() || is_front_page() ) {
     3282                $link = get_home_url(null, '/');
     3283        } else if ( is_search() ) {
     3284                global $wp_the_query;
     3285                if ( empty( $wp_the_query->query_vars['s'] ) ) {
     3286                        return;
     3287                }
     3288                $link = esc_url(
     3289                        add_query_arg(
     3290                                's',
     3291                                $wp_the_query->query_vars['s'],
     3292                                get_home_url(null, '/')
     3293                        )
     3294                );
     3295        }
    32793296
    3280         if ( $page = get_query_var('cpage') )
    3281                 $link = get_comments_pagenum_link( $page );
    3282 
    3283         echo "<link rel='canonical' href='$link' />\n";
     3297        if ( $link ) {
     3298                echo "<link rel='canonical' href='$link' />\n";
     3299        }
    32843300}
    32853301
    32863302/**