Disable wp_enqueue_styles action for specific page

I have an specific page on my website where I can’t have any stylesheets being enqueued, so I need to unenqueue all stylessheets loaded there. Problem is I don’t know their IDs, because they can come from either several different themes or other plugins.

What I’ve tried to do is remove the wp_enqueue_styles action, but without luck.

Read More

Here’s what I’ve tried:

add_action( 'init', 'remove_enqueue_action', 99);
function remove_enqueue_action() {
    remove_action( 'wp_enqueue_styles','' );
}

Any help is appreciated.

Related posts

3 comments

  1. Check the $wp_styles global to get the stylesheet IDs.

    global $wp_styles;
    var_dump($wp_styles);
    

    Look for the handle key. Or…

    var_dump(array_keys($wp_styles->registered));
    

    That should give you what you need to dequeue them.

  2. it can be done where you are actually enqueue your scripts

    like this

    if(!is_page('page id on which you dont want styles') {
        add_action( 'wp_enqueue_scripts', 'functionname where you enqueue your style' );
    
    }
    
  3. function dequeue_all () {
        global $wp_styles;
        // var_dump($wp_styles->queue);
    
        foreach ($wp_styles->queue as $handle) {
            wp_dequeue_style ($handle);
        }
    }
    add_action('wp_footer', 'dequeue_all', 9999);
    

    Working on that global vars cycling gives you a full array of all the styles loaded at the time you process the same one, so you can dequeue them all just specifying each handle.

Comments are closed.