Post Pic

WordPress trick: Disable plugin stylesheet

When activated, some plugins automatically ads their css stylesheet to your WordPress blog. This is great in most cases, but it is a lot cleaner to have all your css styles in one stylesheet. Here’s a hack to disable plugin specific stylesheets.

The first thing to do is to open the plugin file and find the code which include a plugin-specific stylesheet in the blog header. This function is called wp_enqueue_style(). For example, in case of the useful wp-pagenavi plugin, the code to find is:

wp_enqueue_style('wp-pagenavi', get_stylesheet_directory_uri().'/pagenavi-css.css', false, '2.50', 'all');

What we need to find is the handle. The handle is the first argument of the wp_enqueue_style() function, so in the previous example, wp-pagenavi is the handle we need.

Once done, open your functions.php file and paste the following code in it:

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

function my_deregister_styles() {
	wp_deregister_style( 'wp-pagenavi' );
       // deregister as many stylesheets as you need...
}

Thanks to Justin Tadlock for this great recipe!

14 Responses

Aug 10 2009 11:33

How can i print the css only in a specific 1 or 2 pages?
Thanks

Aug 10 2009 13:54

How do I do this for a Javascript?

Aug 10 2009 14:02

@Viktor: Go here and you’ll get your answer :)

Aug 10 2009 14:28

What a coincidence, I was actually trying to figure out how to disable plugin styles the other day with the PageNavi plugin.

What I eventually did was put a pagenavi-css.css file in my theme directory, which overrides the one in the plugin folder so it’s easier to edit.

Aug 11 2009 00:34

Thanks Jean-Baptiste! … and thanks for the link about the JS disabling!

Aug 11 2009 16:07

Thank you a lot for the trick!

Aug 22 2009 04:23

I’ve done this with a few sites in the past and it really saves time.

I used to just delete the line from the plug-in its self, but that was useless when you end up updating the plug-ins every so often.

Thanks for sharing!

Sep 02 2009 16:07

Ok, I did it and will see if it works!

Sep 08 2009 17:38

Hey – Ive noticed this from time to time but didnt know how to get around it. THANKS for the info!

Sep 13 2009 20:14

Great trick. Thank u.

Oct 07 2009 00:33

just in time. i hate the automatic styling of plugins.

Jan 29 2010 15:54

Smart solutions :) Thanks also i don’t like automatic styling of plugins and changed them manualy

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required