Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Fonts: fix warning when webfonts API not available #23306

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Google Fonts: prevent error when Webfonts API is not available
14 changes: 12 additions & 2 deletions projects/plugins/jetpack/modules/google-fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,15 @@ function jetpack_add_google_fonts_provider() {
}
add_action( 'after_setup_theme', 'jetpack_add_google_fonts_provider' );

// Run on an early priority to print out the preconnect link tag near the start of the page source.
add_action( 'wp_head', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider::preconnect_font_source', 0 );
/**
* Add a preconnect link to the `<head>`, if Webfonts API is available.
*/
function jetpack_add_google_fonts_preconnect() {
if ( ! class_exists( 'WP_Webfonts_Provider' ) ) {
return;
}

// Run on an early priority to print out the preconnect link tag near the start of the page source.
add_action( 'wp_head', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider::preconnect_font_source', 0 );
}
add_action( 'init', 'jetpack_add_google_fonts_preconnect' );