Search code examples
wordpressstylesheet

How do I deregister style sheet from wordpress using functions.php?


I found this article here on how to deregister styles in wordpress. techotronic.de/how-to-de-register-style-sheet-wordpress/

Pretty simples I thought but I can't get my head round what he's trying to say. This is the code below...

add_action( 'wp_print_styles', 'custom_deregister_styles', 100 );

function custom_deregister_styles() {

  wp_deregister_style( 'colorbox-theme1' );

}

Straight forward enough, for his plugin...

But if I wanted to deregister a style from another plugin I'm using, how do you find out what name to put in the code - wp_deregister_style( ' ???? ' );

I've tried the obvious, the stylesheet name...

add_action( 'wp_print_styles', 'custom_deregister_styles', 100 );
function custom_deregister_styles() {
  wp_deregister_style( 'language-selector.css' );
}

and this is another method I found, but can't get my head around what I got to do?

add_action("gform_enqueue_scripts", "deregister_style");
    function deregister_style(){
wp_deregister_style("gforms_css");
}

How does this deregister method work, and what do I need to look for in the plugin to get the relative name to get it to work. I'm very confused.

Appreciate any advice thanks!


UPDATE

I have just discovered the style sheet I'm trying to deregister is not loaded via wp_enqueue_style or wp_register_style.

See php file from plugin here https://gist.github.com/1442470

And look on Line 792 for language-selector.css


Solution

  • Find wp_register_style or wp_enqueue_style in the plugin folder. You'll find the name in that function call.

    Update: You cannot remove this without editing the plugin, or resolving to ugly hacks like buffering all the output and filtering it at the end. That's the reason wp_enqueue_style or wp_register_style should be used for all stylesheets.