Remove Google Fonts Which Are (Probably) Added By Plugins

I’ve a theme which loads ‘Open Sans’ from Google Fonts. Our site is using SSL & we’re using a $protocol:// to render the font URL

However, I noticed that, some plugin/(s) probably adding 3 different fonts from Google Fonts, & they’re being loaded using http:// & that throws error such as:

Blocked loading mixed active content "http://fonts.googleapis.com/css?family=Lato:300,400,700"

Question: How do we disable fonts loaded from plugins, on the frontend, since they’re not used in visual sense of the website

Thanks in advance 🙂

2 s
2

If the fonts are loaded from a plugin, a hook will have to be used to insert them, you can disable the hook, but you’ll need to know where it’s coming from. Mostly because you’ll need the handle of the script.

There are quite a few different ways it could be done so I’ll try to give an example of one way it may be done, but there’s a good chance you’ll need to do some hunting yourself.

The plugin could be (ideally is) loading it directly with wp_enqueue_style(), lucky for us there’s a function for reversing that action wp_dequeue_style(), you just need to make sure you hook in at the right time and you can remove it. In most cases this is done in the wp_enqueue_scripts hook. It’s possible they have set a high priority to make it load late, but that’s not usually necessary, you may need to find exactly how they do it to be sure.

somewhere in the plugin may be a few lines of code something like:

add_action( 'wp_enqueue_scripts', 'plugin_setup_styles' );

function plugin_setup_styles() {
  // it may not be quite this simple, depending on what the plugin is doing
  wp_register_style( 'plugin-google-font-lato', 'http://fonts.googleapis.com/css?family=Lato:300,400,700' );
  wp_enqueue_style( 'plugin-google-font-lato' );
}

possible solution, should work from functions.php:

add_action( 'wp_enqueue_scripts', function() {
  wp_dequeue_style( 'plugin-google-font-lato' );
}, 99 );

Basically, you’re going to need to know the handle of the script as it is registered, grep is great for this $ grep -R wp_enqueue_style wp-content/plugins/ as a start. But you may get better results searching for Lato $ grep -Rn Lato wp-content/plugins/

Leave a Comment