Make WordPress Core


Ignore:
Timestamp:
10/23/2016 01:55:49 AM (10 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/twentytwelve/functions.php

    r38093 r38870  
    157157}
    158158add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
     159
     160/**
     161 * Add preconnect for Google Fonts.
     162 *
     163 * @since Twenty Twelve 2.2
     164 *
     165 * @param array   $urls          URLs to print for resource hints.
     166 * @param string  $relation_type The relation type the URLs are printed.
     167 * @return array URLs to print for resource hints.
     168 */
     169function twentytwelve_resource_hints( $urls, $relation_type ) {
     170        if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
     171                if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
     172                        $urls[] = array(
     173                                'href' => 'https://fonts.gstatic.com',
     174                                'crossorigin',
     175                        );
     176                } else {
     177                        $urls[] = 'https://fonts.gstatic.com';
     178                }
     179        }
     180
     181        return $urls;
     182}
     183add_filter( 'wp_resource_hints', 'twentytwelve_resource_hints', 10, 2 );
    159184
    160185/**
Note: See TracChangeset for help on using the changeset viewer.