automattic / jetpack-google-fonts-provider
WordPress Webfonts provider for Google Fonts
Installs: 9 111
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 6
Forks: 1
Type:jetpack-library
Requires
- php: >=7.0
Requires (Dev)
- automattic/jetpack-changelogger: ^4.2.5
- brain/monkey: 2.6.1
- yoast/phpunit-polyfills: 1.1.0
Suggests
- automattic/jetpack-autoloader: Allow for better interoperability with other plugins that use this package.
README
Jetpack Google Fonts Provider Package
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.
How to install google-fonts-provider
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" }
Usage
The WordPress Webfonts API is available by activating the Gutenberg plugin and is planned to be included in WordPress 6.0.
Register the provider
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' );
Register fonts
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', ), );
Add preconnect link
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 );
Additional info
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/.
Using this package in your WordPress plugin
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.
Security
Need to report a security vulnerability? Go to https://automattic.com/security/ or directly to our security bug bounty site https://hackerone.com/automattic.
License
Jetpack Google Fonts Provider is licensed under GNU General Public License v2 (or later)