0

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?

2

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

FEW NOTES

  • 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.

  • You meant "wp_enqueue_style" right? – drake035 Feb 8 '15 at 12:11
  • No specially talked about the hook here :-). 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 – Pieter Goosen Feb 8 '15 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.