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/twentyfourteen/functions.php

    r38093 r38870  
    277277}
    278278add_action( 'admin_print_scripts-appearance_page_custom-header', 'twentyfourteen_admin_fonts' );
     279
     280/**
     281 * Add preconnect for Google Fonts.
     282 *
     283 * @since Twenty Fourteen 1.9
     284 *
     285 * @param array   $urls          URLs to print for resource hints.
     286 * @param string  $relation_type The relation type the URLs are printed.
     287 * @return array URLs to print for resource hints.
     288 */
     289function twentyfourteen_resource_hints( $urls, $relation_type ) {
     290    if ( wp_style_is( 'twentyfourteen-lato', 'queue' ) && 'preconnect' === $relation_type ) {
     291        if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
     292            $urls[] = array(
     293                'href' => 'https://fonts.gstatic.com',
     294                'crossorigin',
     295            );
     296        } else {
     297            $urls[] = 'https://fonts.gstatic.com';
     298        }
     299    }
     300
     301    return $urls;
     302}
     303add_filter( 'wp_resource_hints', 'twentyfourteen_resource_hints', 10, 2 );
    279304
    280305if ( ! function_exists( 'twentyfourteen_the_attached_image' ) ) :
Note: See TracChangeset for help on using the changeset viewer.