2

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.

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.

  • Follow up: I also tried this without luck: <?php add_action('get_header', 'remove_widget_action'); function remove_widget_action() { remove_action( 'get_header', 'wp_enqueue_style',99 ); remove_action( 'get_header', 'wp_register_style',99 ); } ?> – Eduardo Soubihe Sep 4 '13 at 21:26
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.

| improve this answer | |
  • Thank you but this does not list a style registered through the theme. IE: function woo_load_frontend_css () {wp_register_style( 'woo-layout', get_template_directory_uri() . '/css/layout.css' ); wp_enqueue_style( 'woo-layout' ); } // End woo_load_frontend_css() – Eduardo Soubihe Sep 4 '13 at 20:44
  • Yes, it does actually, if you run it after the theme has registered the stylesheet. – s_ha_dum Sep 5 '13 at 1:55
-1

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' );

}
| improve this answer | |
  • This is not only about stylesheets enqueued by the user but about all of them. The question says "I can't have any stylesheets being enqueued"... – tfrommen Sep 5 '13 at 11:15
-1
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.

| improve this answer | |
  • 1
    Please add an explanation to your answer: why and how could that solve the problem? See also: How to Answer – fuxia Sep 4 '13 at 20:00
  • Thank you @mirkolofio that successfully unenqueue all wp styles, but it didn't unenqueued the theme stylesheet. – Eduardo Soubihe Sep 4 '13 at 20:02
  • @EduardoSoubihe Is it even enqueued? Or is the theme's stylesheet hard-coded in the theme's header.php file? – tfrommen Sep 5 '13 at 7:14
  • That's coz you need to run that code after the theme-code has run. Try this one: dequeue_all.php This one should work 'cause it will be run after the theme il loaded, thanks to the hook at wp_footer. – mircobabini Sep 5 '13 at 7:21
  • Can you tell us if the purposed solution does the trick thank to the wp_footer hook? Thanks. – mircobabini Jan 8 '14 at 15:29

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.