+/**
+ * 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 );
+