Skip to content

Issues with URLs of some embedded fonts returning 404 #14

@marcochiesi

Description

@marcochiesi

Hi there,
thanks for this useful plugin. I have found a bug when using the Kanit font with the following enqueue:

wp_enqueue_style( 'google-font', 'https://fonts.googleapis.com/css?family=Kanit:100,200,300,400,400,500,700,900&display=swap' );

Basically, there was a mismatch between the file name in the local cache and the URL used as a replacement in the link.

I.e. The file was named kanit-v13-latin_latin-ext_thai_vietnamese-100.woff but the URL was kanit-v12-vietnamese_latin-ext_latin-regular.woff2, resulting in several 404 errors.

There were two different issues:

  1. The "thai" subset was completely missing
  2. It seems the order of the subsets in the two cases was not corresponding.

I was able to fix the issue with the following snippet thanks to the available filter:

// Fix to embed Kanit font via Embed Google Fonts plugin.
function bs_fix_embed_google_fonts_get_subsets( $subsets ) {
	if ( ! in_array ( 'thai', $subsets ) ) {
		$subsets[] = 'thai';
	}
	sort( $subsets );
	return $subsets;
}
add_filter( 'embed_google_fonts_get_subsets', 'bs_fix_embed_google_fonts_get_subsets' );

However, it would be ideal to add 'thai' and reorder the subsets directly in the original plugin.
Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions