Disable A Plugin’s CSS File

WordPress plugins have the ability to include their own CSS files and most of the time this is great. Good plugins will write selectors that only affect the plugins content but some of the plugins don’t write specific enough CSS or their CSS uses techniques that make it more challenging to override with your own CSS. Regardless of the reason I knew there had to be a better way to allow your own styles to be applied to the content.

I knew that WordPress has the ability to register & deregister script/style files but I was primarily finding solutions which use CSS specificity to override the styles. This works just fine but that’s an awful lot of work I would prefer not to do. Besides, there is no need to override the styles and clutter your own stylesheet when you can simply prevent the file from being sent in the first place.

All you have to do is add an action right before the styles are sent to the browser.

In this action you simply list the handle(s) of the file(s) you want to ignore. You can easily find the handle in the plugin’s file in the wp_enqueue_style() method. You can dequeue as many files as you need inside of the┬ámytheme_dequeue_css_from_plugins() function. You can even dequeue script files if you need to.

One thought on “Disable A Plugin’s CSS File

  1. Widget styles are enqueue-d at a later stage. You can handle these by also deregistering the style. So after the dequeue method also call:

    wp_deregister_style( “plugin-css-file-handle” );

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>