Make WordPress Core


Ignore:
Timestamp:
10/23/2016 01:55:49 AM (8 years ago)
Author:
peterwilsoncc
Message:

Bundled theme: Add preconnect to fonts.gstatic.com in 2012-15 themes.

Add preconnect hinting for https://fonts.gstatic.com in the bundled themes using Google fonts. WordPress versions 4.7+ include a crossorigin attribute, earlier versions will not.

Props leobaiano, swissspidy, peterwilsoncc.
Fixes #37171.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentythirteen/functions.php

    r38093 r38870  
    190190}
    191191add_action( 'wp_enqueue_scripts', 'twentythirteen_scripts_styles' );
     192
     193/**
     194 * Add preconnect for Google Fonts.
     195 *
     196 * @since Twenty Thirteen 2.1
     197 *
     198 * @param array   $urls          URLs to print for resource hints.
     199 * @param string  $relation_type The relation type the URLs are printed.
     200 * @return array URLs to print for resource hints.
     201 */
     202function twentythirteen_resource_hints( $urls, $relation_type ) {
     203    if ( wp_style_is( 'twentythirteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
     204        if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
     205            $urls[] = array(
     206                'href' => 'https://fonts.gstatic.com',
     207                'crossorigin',
     208            );
     209        } else {
     210            $urls[] = 'https://fonts.gstatic.com';
     211        }
     212    }
     213
     214    return $urls;
     215}
     216add_filter( 'wp_resource_hints', 'twentythirteen_resource_hints', 10, 2 );
    192217
    193218/**
Note: See TracChangeset for help on using the changeset viewer.