• chlitto

    (@chlitto)


    When using Google Fonts with variable weights, the plugin fails to generate a working local font link if the weight definition contains two dots next to each other ( e.g. https://fonts.googleapis.com/css2?family=League+Spartan:wght@100..900&family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap ).

    Some of the bad reviews this plugin has are probably cause by this bug since basically 90% the fonts I use have two dots and don’t work with it.

    Solution:
    In local-google-fonts/includes/class-local-google-fonts-parser.php, after cleaning the $font_weight string, add a replacement to convert spaces into dashes. This ensures that variable weights are formatted correctly in the local font URLs.

    $font_weight = null;
    if ( isset( $matched_font_weights[ $i ][0] ) ) {
    $font_weight = rtrim( ltrim( $matched_font_weights[ $i ][0], ‘font-weight:’ ), ‘;’ );
    $font_weight = trim( str_replace( array( “‘”, ‘;’ ), ”, $font_weight ) );
    $font_weight = str_replace( ‘ ‘, ‘-‘, $font_weight );
    }

    • This topic was modified 8 months ago by chlitto.

The topic ‘Variable font weights with dots are not linked correctly’ is closed to new replies.