Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created December 13, 2022 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hellofromtonya/04630045ed76265405b198e0b6a51dd1 to your computer and use it in GitHub Desktop.
Save hellofromtonya/04630045ed76265405b198e0b6a51dd1 to your computer and use it in GitHub Desktop.
Web Fonts API architectural changes

Web Fonts API architectural changes

Web fonts array passed to wp_register_webfonts() changed:

Original API: each variation identifies its font-family.

wp_register_webfonts(
     array(
         array(
             'provider'    => 'local',
             'font-family' => 'Source Serif Pro',
             'font-weight' => '200 900',
             'font-style'  => 'normal',
             'src'         => get_theme_file_uri( 'assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2' ),
         ),
         array(
             'provider'    => 'local',
             'font-family' => 'Source Serif Pro',
             'font-weight' => '200 900',
             'font-style'  => 'italic',
             'src'         => get_theme_file_uri( 'assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2' ),
         ),
     )
);

New API: variations are grouped to their font-family.

wp_register_webfonts(
     array(
         'Source Serif Pro' => array(
             array(
                 'provider'    => 'local',
                 'font-weight' => '200 900',
                 'font-style'  => 'normal',
                 'src'         => get_theme_file_uri( 'assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2' ),
             ),
             array(
                 'provider'    => 'local',
                 'font-weight' => '200 900',
                 'font-style'  => 'italic',
                 'src'         => get_theme_file_uri( 'assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2' ),
             ),
         ),
     )
);
Functionality Original New
Get enqueued web fonts WP_Webfonts::get_registered_webfonts() WP_Webfonts::get_registered()
Get all web fonts WP_Webfonts::get_all_webfonts() WP_Webfonts::get_registered()
Register web font WP_Webfonts::register_webfont() WP_Webfonts::add_variation()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment