Zum Inhalt springen

Get rid of Google Fonts API in the WordPress Theme „Chosen“

The plugins „Disable Google Fonts“ and „Remove Google Fonts References“ don’t work, since the theme is not using the function „wp_enqueue_script“ to load fonts directly from Google.

What works is a combination of the plugin „CAOS for Webfonts“ and the plugin „Autoptimize“ – check the „Extras“ area. „CAOS for Webfonts“ creates a file in /wordpress/wp-content/cache/caos-webfonts/fonts.css.

This css file is loaded in the sequence before we other css files, so it can be used to load the fonts that are used by the theme. Load the fonts (use fontsquirrel to get and transform them / or download the fonts from Google and then transform them with fontsquirrel) into a folder next to the font.css style sheet and refer to them in the style sheet:

/** This file is automagically generated by CAOS for Webfonts
  *
  * @author: Daan van den Bergh
  * @copyright: (c) 2019 Daan van den Bergh
  * @url: https://daan.dev
  */

@font-face {
    font-family: 'Raleway';
    src: url('zazufonts/raleway-regular-webfont.woff2') format('woff2'),
         url('zazufonts/raleway-regular-webfont.woff') format('woff');
    font-weight: normal;
    font-style: normal;

}




@font-face {
    font-family: 'Playfair Display';
    src: url('zazufonts/playfairdisplay-regular-webfont.woff2') format('woff2'),
         url('zazufonts/playfairdisplay-regular-webfont.woff') format('woff');
    font-weight: normal;
    font-style: normal;

}


In the same „caos-webfonts“ folder you have now to put a folder „zazufonts“ with the fonts that have been generated by fontsquirrel. https://www.fontsquirrel.com/

Why should you not download fonts from Google directly?
Just to get the world back into balance and avoid a bloody data war in the future. Or just google it so you can learn why not to use Google. 🙂

Author: Thomas Hezel

    Schreibe einen Kommentar

    Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert