1

I want to perform action when scripts are loaded. I mean when scripts are enqueued i want to take some action.

Is there a hook after_wp_enqueue_scripts?

  • Action for what? What code are referring to? – Brad Dalton Apr 25 '14 at 14:27
4

You can hook into wp_enqueue_scripts very late, using the priority argument of add_action. For example:

function hook_really_late() {
  echo 'Should reasonably be last';
}
add_action('wp_enqueue_scripts','hook_really_late',PHP_INT_MAX);

PHP_INT_MAX should be the highest number assignable as a priority. It is possible that some other code uses the same trick though. That is still probably what I'd recommend.

If you must be absolutely sure, wp_enqueue_scripts runs on the wp_head hook which is called by wp_head() so a similar trick should give you a very slightly better chance of running your code just after the scripts enqueue. Since wp_enqueue_scripts is hooked with a priority of 1, you'd want to use a priority of 1 also, or of 2. Since wp_enqueue_scripts is hooked by Core even with a priority of 1 your code should still come later than wp_enqueue_scripts but before anything else (with a reasonable margin of error).

function hook_really_late() {
  echo 'Should reasonably be last';
}
add_action('wp_head','hook_really_late',1);

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.