Skip to content

Commit

Permalink
allow themes to specify which fonts to preload
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Mar 11, 2022
1 parent 529103a commit 9f5fb53
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/compat/wordpress-6.0/class-wp-webfonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public function validate_font( $font ) {
'font-feature-settings',
'font-variation-settings',
'line-gap-override',
'preload',
'size-adjust',
'src',
'unicode-range',
Expand Down Expand Up @@ -307,13 +308,15 @@ public function generate_styles() {
*/
public function preload_webfonts() {
foreach ( $this->get_fonts() as $font ) {
foreach( $font['src'] as $src ) {
$srcAsArray = explode( '.', $src );
$file_type = end( $srcAsArray );
if ( ! in_array( $file_type, self::$allowed_types ) ) {
$file_type = '';
if ( $font['preload'] ) {
foreach( $font['src'] as $src ) {
$srcAsArray = explode( '.', $src );
$file_type = end( $srcAsArray );
if ( ! in_array( $file_type, self::$allowed_types ) ) {
$file_type = '';
}
echo '<link rel="preload" href="' . $src . '" as="font" type="font/' . $file_type . '" crossorigin />';
}
echo '<link rel="preload" href="' . $src . '" as="font" type="font/' . $file_type . '" crossorigin />';
}
}
}
Expand Down

0 comments on commit 9f5fb53

Please sign in to comment.