Make WordPress Core

Changeset 43606 for trunk


Ignore:
Timestamp:
09/03/2018 12:52:53 AM (6 years ago)
Author:
peterwilsoncc
Message:

Twenty Sixteen: Add pre-connect resource hint for Google Fonts.

When using Google Fonts, pre-connect to https://fonts.gstatic.com to improve the performance downloading the webfont files.

Props westonruter.
Fixes #44668.

File:
1 edited

Legend:

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

    r43571 r43606  
    157157
    158158/**
     159 * Add preconnect for Google Fonts.
     160 *
     161 * @since Twenty Sixteen 1.6
     162 *
     163 * @param array  $urls           URLs to print for resource hints.
     164 * @param string $relation_type  The relation type the URLs are printed.
     165 * @return array $urls           URLs to print for resource hints.
     166 */
     167function twentysixteen_resource_hints( $urls, $relation_type ) {
     168    if ( wp_style_is( 'twentysixteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
     169        $urls[] = array(
     170            'href' => 'https://fonts.gstatic.com',
     171            'crossorigin',
     172        );
     173    }
     174
     175    return $urls;
     176}
     177add_filter( 'wp_resource_hints', 'twentysixteen_resource_hints', 10, 2 );
     178
     179/**
    159180 * Registers a widget area.
    160181 *
Note: See TracChangeset for help on using the changeset viewer.