Blocking Google Fonts in wordpress website

If you check your source code and look for “fonts.” you will find a line that is calling the stylesheet. This could be “googleapis.com” or “google.com or other URL. Here’s how mine looks (using Astra theme);

<link rel="stylesheet" id='astra-google-fonts-css' href="https://fonts.googleapis.com/css?family=Roboto%3A400%2C&#038;display=fallback&#038;ver=4.0.2" media="all" />

Make note of the ID (astra-google-fonts-css) and then add the following to your functions file;

function remove_google_fonts() {  
    wp_dequeue_style( 'astra-google-fonts' ); // do not include the "-css" part
}
add_action( 'wp_enqueue_scripts', 'remove_google_fonts', 999 );

As you’ll see above, I now reference the ID but leave off the “-css” part from the stylesheet ID.

Of course, it’s best to edit the theme and not call the fonts to begin with, but this should help with the call out reference.