[wp-trac] [WordPress Trac] #46370: A proposal for creating an API to register and enqueue web fonts

WordPress Trac noreply at wordpress.org
Tue Sep 28 19:25:16 UTC 2021


#46370: A proposal for creating an API to register and enqueue web fonts
--------------------------------------+-----------------------------------
 Reporter:  jonoaldersonwp            |       Owner:  (none)
     Type:  feature request           |      Status:  new
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  General                   |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  performance, privacy
--------------------------------------+-----------------------------------

Comment (by flixos90):

 I left a comment in
 https://make.wordpress.org/core/2021/09/28/implementing-a-webfonts-api-in-
 wordpress-core/#comment-41880, but wanted to cross-post here: The proposed
 API looks solid to me from a perspective of bundled fonts, but the
 approach has limitations when it comes to API-based fonts.

 When loading API-based fonts, it is possible to load multiple fonts at a
 time, so using `wp_enqueue_webfont` like that feels off from an API
 perspective. It may even be preferred to e.g. make one request to
 `https://fonts.googleapis.com/css2` with 6 fonts rather than three
 requests to `https://fonts.googleapis.com/css2` with 2 fonts each. In
 addition, the two usages currently function quite differently, essentially
 using one function but with entirely different ways to call it.

 If the API supported a way to register a fonts API "provider" and specify
 details like root URL and possibly even how it combines font parameters as
 part of that registration, we could then enqueue such web fonts in a more
 intuitive way that is closer to how the API works for bundled fonts. For
 example (given there is a provider "google"):
 {{{#!php
 <?php
 wp_enqueue_webfont( 'my-font', '', array(
     'font-family'  => 'My Font',
     'font-display' => 'swap',
     'font-style'   => 'normal',
     'font-weight'  => '400',
     'provider'     => 'google',
 ) );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46370#comment:38>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list