Make WordPress Core

Changeset 38870


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.

Location:
trunk/src/wp-content/themes
Files:
4 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 *
  • 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' ) ) :
  • 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/**
  • 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.