[READ ONLY] WordPress Webfonts provider for Google Fonts This repository is a mirror, for issue tracking and development head to: https://github.com/automattic/jetpack
OTHER License
WordPress Webfonts provider for Google Fonts
[!CAUTION] This package is abandoned. It depends on an API provided by the Gutenberg plugin between versions v12.8.0 and v16.3.0, which never made it into WordPress Core and is now non-functional in Gutenberg as well.
Package is published in Packagist. We recommend using the latest version there. You can install it in a composer managed project with composer require automattic/jetpack-google-fonts-provider
.
You can also test with the latest development versions like below:
"require": {
"automattic/jetpack-google-fonts-provider": "dev-trunk"
}
The WordPress Webfonts API is available by activating the Gutenberg plugin and is planned to be included in WordPress 6.0.
This package contains the provider class, but the provider needs to be registered before it can be used.
wp_register_webfont_provider( 'google-fonts', '\Automattic\Jetpack\Fonts\Google_Fonts_Provider' );
After registering the provider, you can register any of the fonts available in the Google Fonts catalog to make them available for use in the block editor typography settings, Global styles, and your site's CSS.
wp_register_webfont(
array(
'font-family' => 'Lato',
'provider' => 'google-fonts',
),
);
Adding a preconnect link to the <head>
of the page will help make sure the font files load as soon as possible, and reduce the layout shift when they are displayed. See this list of webfont best practices for more details. To do so, we can rely on WordPress' wp_resource_hints
filter like so:
add_filter( 'wp_resource_hints', '\Automattic\Jetpack\Fonts\Utils::font_source_resource_hint', 10, 2 );
For a discussion about the Webfonts API in WordPress, see https://make.wordpress.org/core/2021/09/28/implementing-a-webfonts-api-in-wordpress-core/.
If you plan on using this package in your WordPress plugin, we would recommend that you use Jetpack Autoloader as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well.
Need to report a security vulnerability? Go to https://automattic.com/security/ or directly to our security bug bounty site https://hackerone.com/automattic.
Jetpack Google Fonts Provider is licensed under GNU General Public License v2 (or later)