1

I'd like to add something to wp_head() but I'm aiming precise location (like after style.css but before rtl.css and before my other custom script). I'm wondering if it's possible to list everything that is attached to wp_head() in execution/display order anyhow?

I know that I can pass priority/order parameter to add_action but I need to know what number will that be.

add_action( 'wp_head', 'my_function', 10 );

It all starts with 10 but somehow rtl.css seems to be always after style.css. Is it 11 maybe? How do I find that out?

1

1 Answer 1

3

While you can practically control order of hooked things by priority, it's not always the right tool for the job.

In case of styles you should be using appropriate wp_enqueue_style() function which allows you to easily set up elaborate dependencies which will be automagically processed by WP to produce desired order of styles output.

Unfortunately while there is analogous wp_enqueue_scripts() for scripts, you cannot cross-depend scripts and styles like your question indicates. However it is common practice to not start JS execution until page has fully downloaded, so in most cases explicit depending on CSS should not be necessary.

1
  • Thanks! I was actually trying to create a <style> tag with user CSS. This can't be done with wp_enqueue_style unless a new CSS file is created. So, it's an exception :)
    – Paul
    May 9, 2013 at 10:10

Your Answer

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

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