WordPress.org

Make WordPress Core


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

    r38846 r38870  
    287287
    288288/**
     289 * Add preconnect for Google Fonts.
     290 *
     291 * @since Twenty Fifteen 1.7
     292 *
     293 * @param array   $urls          URLs to print for resource hints.
     294 * @param string  $relation_type The relation type the URLs are printed.
     295 * @return array URLs to print for resource hints.
     296 */
     297function twentyfifteen_resource_hints( $urls, $relation_type ) {
     298    if ( wp_style_is( 'twentyfifteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
     299        if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
     300            $urls[] = array(
     301                'href' => 'https://fonts.gstatic.com',
     302                'crossorigin',
     303            );
     304        } else {
     305            $urls[] = 'https://fonts.gstatic.com';
     306        }
     307    }
     308
     309    return $urls;
     310}
     311add_filter( 'wp_resource_hints', 'twentyfifteen_resource_hints', 10, 2 );
     312
     313/**
    289314 * Add featured image as background image to post navigation elements.
    290315 *
Note: See TracChangeset for help on using the changeset viewer.