I want to override my plugin CSS settings, but I can’t do that in my style.css
file, because the plugin CSS gets loaded after.
Is there a way of getting style to be applied to override plugin CSS?
I want to override my plugin CSS settings, but I can’t do that in my style.css
file, because the plugin CSS gets loaded after.
Is there a way of getting style to be applied to override plugin CSS?
Comments are closed.
Will be interesting know which answer developers think is ‘better’, so as an alternative to Johanne’s answer (which can present difficulties if the plug-in loads scripts late, or starts moving them around without warning)
Prevent the stylesheet from loading
If you’ve included all necessary styling in your
style.css
then you can prevent the plug-in’s stylesheet from loading:This has the advantage of not requiring additional stylesheets to be loaded – but the plug-in’s CSS is then included in all page loads, so this may not be desirable.
Replacing the stylesheet
Otherwise, you can copy the stylesheet into your theme, edit and then ensure WordPress uses it instead:
Include overrides after wp_head / wp_footer actions
The plugin’s stylesheet(s) are most likely inserted into the page using WordPress’ enqueue functions.
If so, scripts and stylesheets will be added either where
wp_head()
is located (usually a theme’s header.php file, the default location) or wherewp_footer()
is (usually a theme’s footer.php file, if so specified in the enqueue parameters), respectively.Hence, if you want to override plugin css, the stylesheet responsible should be loaded at a later point.
Going with the default option of the sheet being inserted into the header, a mock-up snippet of header code could look like this:
Proper Enqueueing with dependencies
Alternatively, you could (should) properly enqueue the stylesheet with the overrides yourself and make it dependent (WP will then load it after the dependency) on the plugin’s stylesheet.
In order to be able to do so, you’d have to examine the plugin code, and find the handle of the stylesheet to reference it as a dependency when registering your own.
cd /path/to/plugin && grep -r wp_enqueue_style .
from a *nix shell should help you out.Then, in your theme’s functions.php file, you’d add the following:
If you just want to override one class, for example
.plugin-class {width: 100px;}
, you can just add the same class to yourstyle.css
file and add !important to it and that will override it.