When is it too late to call the action wp_enqueue_scripts?

The function wp_enqueue_scripts— with an ‘s’– is used as a callback to wp_head. All that the function wp_enqueue_scripts does is fire the wp_enqueue_scripts action. So the last time that you would be able to use the action wp_enqueue_scripts is before the wp_enqueue_scripts callback on the wp_head hook.

In terms of theme templates, that means you need to hook it in before get_header, or on a hook that runs early enough in the hook sequence fired as a consequence.

Couple of notes:

  1. It is $GLOBAL not $_GLOBALS— inconsistent, I know.
  2. It works perfectly fine if not hooked to plugins_loaded. That is, just this in the theme’s functions.php: global $myplugin; $myplugin->api();. I can’t say that I know why the hooked version doesn’t work. I’d guess it is simply too early but would have to do some research to workout the mechanics. after_setup_theme works and so does wp_loaded

Leave a Comment

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş