I have written a basic gallery plugin that uses wp_enqueue_style to include a stylesheet on the page. I’d like for the WordPress theme to be able to override the style of the plugin which means I’d like to my plugin to play nice and output the css file before the theme css file.
wp_enqueue_style has a deps
parameter for exactly this requirement. My question is what value should I use for the deps
parameter if I want to say “I depend on the themes css file”?
The current plugin code is incorrect because it uses false
for the deps
parameter:
// Enqueue a CSS style file - see http://codex.wordpress.org/Function_Reference/wp_enqueue_style
wp_enqueue_style('bitvol_galleria_css', BITVOL_GALLERIA_URL . '/bitvolution-image-galleria.css', false, $this->bitvol_galleria_version, 'all' );
First issue – you have dependency backwards. Depending on something means loading after dependency, while you want earlier.
Second issue – theme’s stylesheet doesn’t actually use enqueue, it is usually codded directly in
header.php
file of theme. And since it seems to come beforewp_head()
call – you have no hook to ensure your stylesheet is above it.So this is commonly handled like your workaround – queued stylesheet with option to disable it by code or option in admin.
I thought I’d post my workaround which I’m using until I know the answer to the question…
My workaround is:
style.css
) and modify it as needed.functions.php
:Code to put in
functions.php
:In some respects, this workaround could be the better solution? (because the website performance will be better by minimising the number of CSS resources included in the HEAD section).