6

So I am trying to get rid of a font that a plugin is loading on the front end as I am already loading it myself and it loads every style of the font which I don't need.

Here is my code:

//Remove open sans  
    function custom_dequeue() {
        wp_dequeue_style('et-gf-open-sans');
    }

    add_action( 'wp_enqueue_scripts', 'custom_dequeue' );

//I've also tried
    add_action( 'wp_print_styles', 'custom_dequeue', 9999 );

//Also hooking into: wp_footer, wp_head, wp_print_scripts, 
//all with high priority and default priority to no avail

All these do is move the code from the head to just before the closing </body> tag.

I've contacted the plugin author and the response was the code I already tried. Waiting on another response.

Also, I am positive that I am dealing with the correct handle name. I changed the url of the code so I could locate exactly which line it was that was loading the font. (author has multiple spots that load fonts.)

Any Ideas?

---------------------------------------------

Edit

It gets loaded with this action:

add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts_styles' ) );

And it is enqueued in the function load_scripts_styles

I have tried a high priority on everything.

I'm also using a plugin called query monitor which outputs the order of all the hooks and what plugin is hooking into what along with the function that is doing the hooking. My code is appearing after the plugins code yet all that happens is that it gets moved from the header to the footer. Driving me nuts!

  • How is it enqueued? – birgire Sep 16 '15 at 18:09
  • Did you try a high priority on the 'wp_enqueue_scripts' action hook? I only ask because you didn't show or mention it explicitly. Most plugins and themes these days do styles via that hook, so you're very close, you can add the priority there too. – totels Sep 16 '15 at 18:12
  • @birgire I've edited my post answering your questions. thanks for your help – John_911 Sep 16 '15 at 18:23
  • @totels I've edited my post answering your questions. thanks for your help – John_911 Sep 16 '15 at 18:23
  • 2
    I would guess so. You might also try deregistering it rather than just dequeueing, that way it can't be enqueued without re-registering it or enqueuing again without full parameters. – Milo Sep 16 '15 at 18:43
12

Okay so I figured this one out.

function custom_dequeue() {
    wp_dequeue_style('et-gf-open-sans');
    wp_deregister_style('et-gf-open-sans');

}

add_action( 'wp_enqueue_scripts', 'custom_dequeue', 9999 );
add_action( 'wp_head', 'custom_dequeue', 9999 );

@milo was right. The plugin was re-enqueueing it so the deregistering it got that file to stop loading.

Then the plugin also had another check, where it would register and enqueue another font with the same handle. The action was hooked into wp_head so I added my another action to wp_head and finally got it to stop loading completely!

Thanks for everyone's help!

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.