Making WordPress.org


Ignore:
Timestamp:
11/26/2018 04:51:14 AM (6 years ago)
Author:
dd32
Message:

WordPress.org: hreflang: Add a default x-default hreflang tag and use the canonical URL for singular pages when possible.

Fixes #3947, #3948.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php

    r7600 r7898  
    10901090 */
    10911091function wporg_themes_add_hreflang_link_attributes() {
     1092    if ( is_404() ) {
     1093        return;
     1094    }
     1095
    10921096    wp_cache_add_global_groups( array( 'locale-associations' ) );
    10931097
     
    11361140        );
    11371141
     1142        // Add x-default to the list of sites.
     1143        $sites['x-default'] = (object) array(
     1144            'locale'    => 'x-default',
     1145            'hreflang'  => 'x-default',
     1146            'subdomain' => '',
     1147        );
     1148
    11381149        uasort( $sites, function( $a, $b ) {
    11391150            return strcasecmp( $a->hreflang, $b->hreflang );
     
    11411152
    11421153        wp_cache_set( 'local-sites', $sites, 'locale-associations' );
     1154    }
     1155
     1156    if ( is_singular() ) {
     1157        $path = parse_url( get_permalink(), PHP_URL_PATH );
     1158    } else {
     1159        // WordPress doesn't have a good way to get the canonical version of non-singular urls.
     1160        $path = $_SERVER['REQUEST_URI']; // phpcs:ignore
    11431161    }
    11441162
     
    11471165            'https://%swordpress.org%s',
    11481166            $site->subdomain ? "{$site->subdomain}." : '',
    1149             $_SERVER[ 'REQUEST_URI' ]
     1167            $path
    11501168        );
    11511169
Note: See TracChangeset for help on using the changeset viewer.