Opened 6 years ago
Closed 6 years ago
#46020 closed defect (bug) (duplicate)
API to register and enqueue web fonts
Reported by: | swissspidy | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Themes | Keywords: | |
Focuses: | Cc: |
Description
This is something that was suggested by @jonoalderson at WCUS and discussed with @igrigorik and others.
There could be potential in providing a dedicated API for themes and plugins to register and enqueue web fonts.
At the moment, developers need to build their own solutions for loading fonts from Google Fonts, Typekit, or self-hosted fonts. This makes it hard for others to hook into this process in order to modify or disable the loading of these fonts. Performance and privacy concerns are some of the reasons.
Some use cases that come to mind:
- Google Fonts and Typekit currently don't set `font-display`. One could hook into the font registration to download the font CSS from the provider, enhance it with
font-display
and host it locally. (something like this) - Optimize font registration to request multiple font families from Google Fonts or similar in one request (if supported)
- For performance reasons, one could hook into the font registration to completely disable web fonts and rely on system fonts instead
- For privacy reasons, one could load a font from a different host / CDN
This could be as simple as wp_enqueue_font
at the core, which in the background could end up as a wp_enqueue_style()
call.
When enqueueing a font, one obviously needs to specify a name/family, the provider to load it from (or a URL) font weights, and perhaps other options (font-display
, etc.).
Any suggestions/feedback welcome :-)
Related: #43898
Marking as a duplicate of #46370 since it's directly from @jonoalderson with some more information.