• Resolved Anonymous User 17421175

    (@anonymized-17421175)


    I am working on optimizing a website for a client and I noticed MailOptin loads the fonts that it needs from google using webfont.js script.
    I don’t want to have extra fonts loading on the site, The WordPress theme already loads the fonts it uses.
    How do I disable this in the plugin?
    I tried setting font family everywhere to “inherit from theme” and it did not help…

    BTW I know this is MailOptin loading this script because 1. When I disabled the plugin it disappeared. 2. I used this handy script to find out the Handles for enqueued WordPress scripts and its handle was “mo-google-webfont”.

    add_filter( 'script_loader_tag', 'find_out_script_handles', 10, 3 );
    function find_out_script_handles( $tag, $handle, $src ) {
    	return str_replace( '<script', sprintf(
    		'<script data-handle="%1$s"',
    		esc_attr( $handle )
    	), $tag );
    }

    Meanwhile, I managed to disable it using this script in the functions.php file

    function mo_google_webfont_dequeue_script() {
        wp_dequeue_script( 'mo-google-webfont' );
    }
    add_action( 'wp_print_scripts', 'mo_google_webfont_dequeue_script', 100 );

    I think this is a flaw of plugin and it needs to be fixed.
    Thanks

    • This topic was modified 5 years, 10 months ago by Anonymous User 17421175.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Collins Agbonghama

    (@collizo4sky)

    When you create an optin, in the font select dropdown, you can select “Inherit from theme”.

    Thread Starter Anonymous User 17421175

    (@anonymized-17421175)

    I tried setting font family everywhere to “inherit from theme” and it did not help…

    That is what I did!
    I set the font family everywhere in the plugin to “inherit from theme”, And it still added the script, even though it did not load any font.
    <script data-handle="mo-google-webfont" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js"></script>

    Plugin Author Collins Agbonghama

    (@collizo4sky)

    If there are no fonts to load, webfont.js does nothing.

    Just ensure none of your optin has a google font selected as a font family.

    Thread Starter Anonymous User 17421175

    (@anonymized-17421175)

    Right, if it does nothing then why should the plugin load the script?! Its useless and just adds anther request that will affect the performance.

    Why can’t you add a condition that it will load the webfont.js script only if there is a font family that is set to something other than “inherit from theme”?

    Where in the code is the function that queues the script? I want to have a look maybe I can contribute.

    Thread Starter Anonymous User 17421175

    (@anonymized-17421175)

    I barely know PHP but I think this can be an easy fix

    Thread Starter Anonymous User 17421175

    (@anonymized-17421175)

    Or add in the settings a toggle to disable google fonts, It might be easier.

    Plugin Author Collins Agbonghama

    (@collizo4sky)

    Got it. We’ve added it to our todo list.

    Regards.

    Thread Starter Anonymous User 17421175

    (@anonymized-17421175)

    Thank you very much!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Stop loading fonts from Google (webfont.js)’ is closed to new replies.