wp_dequeue_style not working

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!

1
1

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!

Leave a Comment