6

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 Answers 2

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/

4
  • Yeop, that makes a lot of sense. Thank you. Yes, I thought of this but then, I guess 'hunting' can't be skipped. (Lazy me) . . Will give it a try & update again. Cheers :)
    – tushonline
    Sep 11, 2015 at 13:47
  • Another case we did not consider was, @import URLs in CSS files used by plugin. I've managed to get rid of 2 errors so far. But the one for "Roboto" font is still haunting. Not sure from where it's landing on site & View Source isn't showing anything. Thanks for the heads-up. Had to search & manually update those @import uri's.
    – tushonline
    Sep 11, 2015 at 18:35
  • Need more help. Blocked loading mixed active content "http://fonts.googleapis.com/css?family=Roboto:300,100,400" This one is still a mystery. 1) It doesn't show in source code. 2) It doesn't show in any file/plugin 3) It doesn't show up on GtMetrix or any other website's "Waterfall" structure. 4) Only showing up on browsers, which seems weird. TIA :)
    – tushonline
    Sep 18, 2015 at 6:33
  • This could be a config setting in your theme or a plugin, you may be able to find the setting in the DB SELECT * FROM wp_config WHERE option_value LIKE '%oboto%'; failing that I can only think to try disabling plugins until it changes and then digging deeper into the settings.
    – totels
    Sep 18, 2015 at 15:27
1

I wanted to make a comment to mention this but I don't have enough rep yet to do so. I had a problem similar to this and I used a simple plugin as a basis to solve the issue. You might be able to do the same.

Checkout disable-google-fonts on GitHub. It disables various google fonts found in Wordpress themes. You could modify this or use snippets of the code to do what you need.

2
  • I saw this moments ago before checking back here. I don't want to get rid of Google Fonts at once, but only disable the ones were added by plugins. Still will give it shot if it fits in. Thanks a ton.
    – tushonline
    Sep 11, 2015 at 13:49
  • Sorry, but that did not work Dominick. It only removed fonts loaded from the Dashboard, but theme fonts were intact, including those undesired ones: Lato & Roboto. Not sure how a browser detecting them.
    – tushonline
    Sep 11, 2015 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.