Skip to content

[Fonts API] Automatically enqueue all user-selected fonts picked in Global Styles. #40363

@zaguiini

Description

@zaguiini

Enhancement Scope:

To add automatic detection and enqueueing of all user-selected global fonts before printing the fonts (likely within wp_print_fonts()).

What are "user-selected global fonts"?

Fonts that a user selected and saved from the Site Editor > Styles > Typography UI.
Screen Shot 2023-05-03 at 11 09 44 AM

They are "global" because a selection in this UI is intended for global availability throughout the website and content.

How are these fonts made available for user selection?

Fonts defined within a theme's theme.json file are already automatically registered and enqueued within the Fonts API.

For plugins and theme's without a theme.json file, the API does not provide the mechanism to detect or enqueue their fonts when a user selects them.

What problem does this address?

🔹 Plugins and theme's without a theme.json file have been required to provide the detection and enqueuing of their user-selected fonts. This enhancement moves that mechanism and functionality into the Fonts API so that detection and enqueuing are within the API.

Why are the benefits?

  • Easier for extenders: extenders will no longer need to provide or maintain this functionality in their products.
  • Makes the out-of-box enqueuing process more consistent, stable, and predictable.

What is your proposed solution?

Before printing the fonts (likely within the wp_fonts_print(), i.e. as late as possible:

  1. Fetch all of the user-selected global fonts (those fonts that the user picked and saved from the Site Editor > Styles > Typography). Font: Need the font-family handles.
  2. Enqueue those font families.

Metadata

Metadata

Labels

[Priority] HighUsed to indicate top priority items that need quick attention

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions