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:
- It is
$GLOBAL
not$_GLOBALS
— inconsistent, I know. - It works perfectly fine if not hooked to
plugins_loaded
. That is, just this in the theme’sfunctions.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 doeswp_loaded
Related Posts:
- conditionally load javascript & CSS for do_action() calls from plugin
- Difference Between Filter and Action Hooks?
- ajaxurl not defined on front end
- How to add a javascript snippet to the footer that requires jQuery
- How to create an API for my plugin?
- How to override existing plugin action with new action
- Which hook should be used to add an action containing a redirect?
- How to enqueue JavaScripts in a plugin
- WordPress Update Plugin Hook/Action? Since 3.9
- How to include jQuery and JavaScript files correctly?
- Load js/css files only on specific admin UI pages
- Which action for triggering cron “wp”or “init”?
- Get list of scripts / styles and show file which enqueued them
- When can you get current page ID and initialize hooks right after?
- add_action with a class method is causing fatal errors
- How do you use the plugin boilerplate loader class to hook actions and filters?
- jQuery in header or footer
- Enqueue script only when shortcode is used, with WP Plugin Boilerplate
- add_filter OO with parameters
- How do I print a notice only on certain admin pages?
- Do I need to call do_action in my plugin?
- How Do I Load My Action Earlier Enough?
- Which to use to execute code during the saving of a plugin settings page?
- Does WP fire delete_post when trashed posts are automatically deleted?
- How do I conditionally enqueue script for CPT single post type with plugin?
- What’s the earliest point I can get the queried object ID?
- How do I Make a Theme “plugin-ready”?
- Where to enqueue stylesheets for plugin?
- A Post is saved twice or more during add_action(save_post)
- Actions or filters fired when data is saved in a custom table
- In a plugin, why is add_action(‘init’) not executed before the plugin is activated?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- What action is called when drafts are saved?
- Is it possible to create an action hook using do_action() within add_action()?
- How can I hook into existing WordPress Bulk actions?
- Use js script from one plugin in another plugin
- Odd behaviour with submenu link creation
- Script won’t load via plugin class
- Plugin Loading Scripts and Styles on Every Page – Even when not being used
- What is the Difference between directly call a function and call a function using add_action?
- How to add custom content under plugin row in WordPress admin plugin list?
- Define a function outside a class and call the function using action or filter hook
- Create a plugin to change the action to which a function is hooked
- Inserting JS snippet in the footer if there is no wp_footer?
- Can’t get JS code to work with shortcode
- Modifying values with add_action to be sent to db
- How do you output enqueued scripts to an admin page?
- Woocommerce – Hide a Column in Cart Table
- How do I add a javascript file to all admin pages via a plugin?
- Multisite plugin development and wp_enqueue_script
- How to redirect to action on custom page within admin section
- admin_notices not displaying in plugin
- is_page() function doesnt working
- Hook to get image filename when it is uploaded
- How to run an add_action hook for specific page
- Which action is triggered when a theme was modified?
- wp_transition_post_status does not change the status of the post
- How to avoid loading same script twice?
- How to run a external JavaScript file on wp-admin if admin, and other if normal user?
- Getting admin notices working for plugin errors
- Which are the hooks run before/after when a category’s deletion?
- Should action callbacks start with a verb?
- Execute Hook on the footer or header after activating a plugin
- Enqueue scripts in footer
- Loading scripts with wp_register_script and wp_enqueue_script
- An echo line in a transition_post_status action leads to “cannot modify header information – headers already sent by”
- Namespaced action and filter tags
- Adding Dropbox dropin js using wp_enqueue_script
- Where to call wp_enqueue_script in a plugin with custom template?
- Issue plugin commands in admin settings page
- My plugin class doesn’t work! [closed]
- Replacing Scripts in Admin Load_Scripts
- Is there a way to ensure plugin script loads before another script?
- add_action not calling back to function
- Tried in different ways but sidebar not working?
- What stylesheets are available in core?
- Plugin with action ‘save_post’ needs to press publish twice on order to publish
- Adding rewrite rule dynamically
- How to hook a custom user function to a wordpress core ajax action?
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- Unable to change footer using wp_footer action hook
- wp_set_object_terms not updating database without a die()
- How to enqueue or include json file to a plugin
- How to filter content for specific content variable
- load_plugin_textdomain doestn’t work with add_action plugins_loaded
- How to load library scripts in admin from plugins in noConflict wrapper?
- Show error message after exception handled
- I have 2 plugins using the same wp_login action hook and one is not working
- jQuery does not enqueue for my purpose… (before an inline script in the footer)
- Valid filenames for add_action’s first parameter
- Enqueue script globally
- WordPress class, using add_action to call member function does not work
- Where do I put my add_action(… and add_filter(… and do I need to remove them?
- How dynamic action login_form_{action} is working
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- How to get all queries’s results after they have executed?
- WP Plugin Running before jQuery
- wp_localize_script is not adding a global variable for javascript
- Loading Modernizr (or other JavaScript libraries) for use in a plugin