In wp_enqueue_style()
's doc I see the third parameter is for stylesheets to be loaded before the one called by the function.
But is it possible to do the contrary, meaning to instruct WP to load a stylesheet before the theme's stylesheet?
By default, themes usually almost always enqueue scripts and style via the wp_enqueue_scripts
hook with default priority set in add action. This is the add_action()
statement by default
add_action( 'wp_enqueue_scripts', 'my_custom_styles_and_scripts' );
As you can see, a priority is not set in the action, which means that it will default to 10
.
With this in mind, you can use a priority of less than 10
to load your styles and scripts earlier than the theme, keeping in mind, the $deps
parameters should not be set when you enqueue and/or register your styles and scripts
If no priority is set in either plugin or themes, and a styles or scripts is loaded from a child theme or plugin, the plugin style/script will load first, then those in the child theme and then the main (parent) theme's styles and scripts. This is the order in which functions load by default
Within the same function, styles and scripts are loaded in the order they appear inside the function, so the style/script appearing first will load first. Again being said, that is if the $deps
parameters aren't set.
wp_enqueue_scripts
hook is used to hook the function in which you register styles (via wp_enqueue_style() function) and scripts (via the
wp_register_script()` function. Sometimes the naming conventions used in Wordpress can be quite confusing
Commented
Feb 8, 2015 at 16:35