Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am loading scripts via wp_enqueue_scripts in my child theme.

The only problem is that my style.css script get loaded BEFORE plugin scripts, yet I need to override the css in the plugins with my style.css, meaning it has to load AFTER plugin scripts.

I don't want to add "!important" too all of my css styles because that is tedious and could break some of my styling.

I tried adding a priority but it did not effect the loading order at all.

    add_action('wp_enqueue_scripts', 'scripts', 9999);

I would simply like to wp_enqueue_scripts at the very end of the header, just before < /head >. How can it be done? Thanks :-)

UPDATE:

Yay I figured it out!

Simply register the filter with:

    add_action('wp_print_styles', 'scripts');

wp_print_styles loads with a priority of 8, and it still places them in the header because it's a part of wp_head.

I figured this out by looking in wp-includes/default-filters.php, so thanks for the tip! :-)

share|improve this question

3 Answers 3

wp_enqueue_scripts is added per default with a priority of 1 to wp_head. See wp-includes/default-filters.php for details.

You can try to change the priority:

remove_action( 'wp_head', 'wp_enqueue_scripts', 1 );
add_action( 'wp_head', 'wp_enqueue_scripts', 9999 );

But I don’t recommend it. There is probably a good reason for the default value. Some scripts may not work anymore when you change this.

share|improve this answer
    
Unfortunately, doing this causes the entire website to break. –  Nate Jul 4 '12 at 5:47
4  
I don’t believe that, but, yes, side-effects are inevitable. –  toscho Jul 4 '12 at 11:57

I think the more WordPress friendly way to do this is to use wp_enqueue_styles()'s $deps parameter. Assuming the plugin styles are enqueued via wp_enqueue_styles() (which, admittedly, pathetically few are), you list an array of the stylesheet handles that your styles depend on and then they load afterwards.

share|improve this answer

add_action accepts a priority parameter which defaults to 10. Increasing this to a higher value makes your function to execute later. Set it to 20 and see whether it helps.

share|improve this answer
2  
The asker has explained in the question that a later priority of 9999 did not solve the problem and you suggest … 20? Seriously? :) –  toscho Jul 4 '12 at 4:30
1  
Yes, this did not solve the problem as I've stated. –  Nate Jul 4 '12 at 5:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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