How to dequeue a WordPress style using regex?

I need to check with regex on both handle and src for font-awesome (and some variants) expression and dequeue that style.

I need this function to dequeue all Font Awesome stylesheets generated by plugins, since the theme already uses this font.

Read More

The solution I have in mind is something like this (pseudo code):

add_action( 'wp_enqueue_scripts', 'my_automatically_dequeue_scripts', 110 );

function my_automatically_dequeue_scripts() {
    global $wp_styles;
    $stylesheets = $wp_styles->registered;
    foreach ( $stylesheets as $stylesheet ) {
        if( check_with_regex $stylesheet['handle'] and $stylesheet['src'] )
            wp_dequeue_style( 'stylesheet["handle"]' );
    }
}

Your help will be greatly appreciated!

Related posts

Leave a Reply