Make WordPress Core

Opened 4 weeks ago

#65607 new enhancement

Add font-display: swap option when enqueuing/loading Google or local fonts on the frontend

Reported by: kavaiyanirmal Owned by:
Priority: normal Milestone: Awaiting Review
Component: Script Loader Version: 6.5
Severity: normal Keywords:
Cc: Focuses: performance

Description

Problem

When WordPress loads fonts (Google Fonts via wp_enqueue_style or
locally via the Font Library introduced in 6.5), there is no built-in
way for theme/plugin authors to set the font-display CSS descriptor
without manually filtering the generated @font-face output.
font-display: swap is a widely recommended performance best practice
(required by Google PageSpeed / Lighthouse for a passing score) that
prevents invisible text during font load (FOIT) by showing a fallback
font immediately.

Proposed Solution

  1. wp_register_font_face() / wp_enqueue_style() — Add a font_display argument (default: fallback to preserve existing behaviour; allow auto | block | swap | fallback | optional).
  2. Font Library UI (Gutenberg / Site Editor) — Add a "Font display" checkbox or select (e.g. ☑ Use font-display: swap) per font family in the Font Library settings panel so non-developer users can opt in without code.
  3. The selected value should be written into the generated @font-face rule, e.g.: @font-face {

font-family: 'Open Sans';
src: url('...') format('woff2');
font-display: swap; /* <-- new */

}

Why core, not a plugin?

  • Lighthouse/CLS scores penalise missing font-display; themes cannot reliably fix this without core support.
  • Google has already deprecated the &display=swap query parameter approach for self-hosted fonts.
  • All major font plugins (e.g. OMGF, Fonts Plugin) implement this individually — a standard API would eliminate the duplication.

Backward Compatibility

Default value of fallback (or leaving the descriptor absent) keeps
existing behaviour unchanged.

References

Change History (0)

Note: See TracTickets for help on using tickets.