Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#46020 closed defect (bug) (duplicate)

API to register and enqueue web fonts

Reported by: swissspidy's profile 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:

  1. 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)
  2. Optimize font registration to request multiple font families from Google Fonts or similar in one request (if supported)
  3. For performance reasons, one could hook into the font registration to completely disable web fonts and rely on system fonts instead
  4. 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

Change History (1)

#1 @ocean90
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Marking as a duplicate of #46370 since it's directly from @jonoalderson with some more information.

Note: See TracTickets for help on using tickets.