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.

Built from https://develop.svn.wordpress.org/trunk@38870


git-svn-id: http://core.svn.wordpress.org/trunk@38813 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2016-10-23 01:56:32 +00:00
parent e73ba84b04
commit 8db6c6c4ef
5 changed files with 101 additions and 1 deletions

View File

@ -285,6 +285,31 @@ function twentyfifteen_scripts() {
} }
add_action( 'wp_enqueue_scripts', 'twentyfifteen_scripts' ); add_action( 'wp_enqueue_scripts', 'twentyfifteen_scripts' );
/**
* Add preconnect for Google Fonts.
*
* @since Twenty Fifteen 1.7
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array URLs to print for resource hints.
*/
function twentyfifteen_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'twentyfifteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
} else {
$urls[] = 'https://fonts.gstatic.com';
}
}
return $urls;
}
add_filter( 'wp_resource_hints', 'twentyfifteen_resource_hints', 10, 2 );
/** /**
* Add featured image as background image to post navigation elements. * Add featured image as background image to post navigation elements.
* *

View File

@ -277,6 +277,31 @@ function twentyfourteen_admin_fonts() {
} }
add_action( 'admin_print_scripts-appearance_page_custom-header', 'twentyfourteen_admin_fonts' ); add_action( 'admin_print_scripts-appearance_page_custom-header', 'twentyfourteen_admin_fonts' );
/**
* Add preconnect for Google Fonts.
*
* @since Twenty Fourteen 1.9
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array URLs to print for resource hints.
*/
function twentyfourteen_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'twentyfourteen-lato', 'queue' ) && 'preconnect' === $relation_type ) {
if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
} else {
$urls[] = 'https://fonts.gstatic.com';
}
}
return $urls;
}
add_filter( 'wp_resource_hints', 'twentyfourteen_resource_hints', 10, 2 );
if ( ! function_exists( 'twentyfourteen_the_attached_image' ) ) : if ( ! function_exists( 'twentyfourteen_the_attached_image' ) ) :
/** /**
* Print the attached image with a link to the next attached image. * Print the attached image with a link to the next attached image.

View File

@ -190,6 +190,31 @@ function twentythirteen_scripts_styles() {
} }
add_action( 'wp_enqueue_scripts', 'twentythirteen_scripts_styles' ); add_action( 'wp_enqueue_scripts', 'twentythirteen_scripts_styles' );
/**
* Add preconnect for Google Fonts.
*
* @since Twenty Thirteen 2.1
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array URLs to print for resource hints.
*/
function twentythirteen_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'twentythirteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
} else {
$urls[] = 'https://fonts.gstatic.com';
}
}
return $urls;
}
add_filter( 'wp_resource_hints', 'twentythirteen_resource_hints', 10, 2 );
/** /**
* Filter the page title. * Filter the page title.
* *

View File

@ -157,6 +157,31 @@ function twentytwelve_scripts_styles() {
} }
add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' ); add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' );
/**
* Add preconnect for Google Fonts.
*
* @since Twenty Twelve 2.2
*
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array URLs to print for resource hints.
*/
function twentytwelve_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
} else {
$urls[] = 'https://fonts.gstatic.com';
}
}
return $urls;
}
add_filter( 'wp_resource_hints', 'twentytwelve_resource_hints', 10, 2 );
/** /**
* Filter TinyMCE CSS path to include Google Fonts. * Filter TinyMCE CSS path to include Google Fonts.
* *

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.7-alpha-38869'; $wp_version = '4.7-alpha-38870';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.