I know wp_enqueue_script has the ability to have a dependency which is great. Now what if I can't give it one? What if all I want is for it to be the last script in the list of generated CSS stylesheets? Themes can be changed out and my dependency is for my stylesheet is to be the last one generated. I want my style to always be the last to override any other stylesheet.

Is there a way to do this without hacking the theme?

1 Answer 1


You can set the priority in hook. Priority is the 3rd parameter in the hook. In the following example, wp_enqueue_scripts will have priority of 99 which is higher than normal priority. Default priority is 10. So it will load at last

function load_last_style() {
    wp_enqueue_style( 'style-name', get_stylesheet_uri() );

add_action( 'wp_enqueue_scripts', 'load_last_style', 99 );
  • Awesome. How in the world did I miss that!
    – Jason
    Commented Jul 1, 2015 at 20:35
  • Say... What if I have 3 CSS stylesheets and they have to be in a certain order at the very end. Will using 97, 98, 99 ensure that 97 is first, 98 second, and 99 dead last or is the priority not a complete guarantee on add_action?
    – Jason
    Commented Jul 1, 2015 at 20:40
  • You can enqueue the other 2 styles depending on the style hooked on 99 priority (let's call it "style-name" as in the previous example). wp_enqueue_style( "last-style-name", get_stylesheet_uri(), array("style-name"))
    – E. Serrano
    Commented Jul 1, 2015 at 22:11
  • I see. So, as long as I have them in the correct order in the array they won't be processed out of order.
    – Jason
    Commented Jul 2, 2015 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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