Enqueue your script instead of putting it in your template, you can enqueue your code as is, or put your code in an actual file.
The benefit of doing this is you gain control over output, as you can see there is a $priority
parameter for add_action
.
add_action( $hook, $function_to_add, $priority, $accepted_args );
Futhermore wp_enqueue_script
comes with two parameters which can alter output, which are $deps
and $in_footer.
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
So with the above 3 settings you can surely change the way the scripts load.
http://codex.wordpress.org/Function_Reference/wp_enqueue_script
http://codex.wordpress.org/Function_Reference/add_action
Related Posts:
- Why is jquery-ui-core enqueueing in my footer instead of the header?
- Which jQueryUI handles are predefined in wordpress?
- Utilizing WordPress’ Admin UI for plugin settings: getting accordion style
- jquery-ui-autocomplete is not loaded with wp_enqueue_script
- Issues with wp_enqueue_script and jquery-ui
- When should I use wp_register_script() with wp_enqueue_script() vs just wp_enqueue_script()?
- How can I get a list of all enqueued scripts and styles?
- Load CSS/Javascript in frontend conditionally if block is used
- How can I de-register ALL styles all at once? And same with Javascript?
- Cannot deregister a script using wp_deregister_script
- Removing specific style from wp_head
- How to dequeue / deregister any theme styles and scripts
- Include jQuery UI as a whole
- Using wp_enqueue_script on shortcode function handler
- Enqueue script only for IE
- Conditionally dequeue dependency of scripts
- wp_enqueue_script vs. wp_register_script
- Adding dependencies to script enqueing
- How to dequeue / deregister parent theme style
- Enqueued scripts and styles loading in WordPress Dashboard as well
- Why is it wrong to use admin_print_scripts-{hook} to enqueue a script (.js) file?
- Enqueueing Scripts on a Custom Top-level Menu Page
- How do I get my page to load the jQuery UI Effects library?
- How to switch css files according to devices and button click?
- Performance-wise, is it better to enqueue a (small) script on every page or test to see if it’s needed?
- Bootstrap js refuses to load
- Stop WordPress editor embedding links
- Enque Typekit Fonts – Not Found
- How to load script-related styles automatically?
- Notice: wp_enqueue_script was called incorrectly
- How to cancel `wp_print_scripts`?
- Do we have to register JQuery if we want to use it in wp_enqueue_script()?
- wp_head() – list hooked actions with priorities?
- Enqueue Style for a page/pages only
- Retrieve URL of Script/Style and Dependencies
- using conditionals on enqueue styles
- debugging js scripts
- Including files in Child Themes
- Can’t load JS File
- Exclude external uri for css and js version
- Do I need to register my own created .js and .css files
- How to enqueu php files with custom variable & conditionals?
- Enqueue never runs
- jQuery UI AutoComplete & wp_enqueue_script
- Unable to dequeue a plugin script. I think I’ve tried everything
- Change script type and src of plugins in theme
- Action hooked on wp_enqueue_scripts running twice
- How to enqueue the script without hardcoded in the theme files?
- Why is .map being added to the end of my file path?
- How can I properly enqueue tags in WordPress to use with Web Components?
- Jquery function working in Dev Console but not otherwise [duplicate]
- Enqueuing script is adding extra text for google maps [closed]
- Custom script file enqueue has “?ver=4.5.1” when loading and doesn’t update
- get_stylesheet_directory() in child theme breaks parent scripts
- Cannot enqueue jQuery correctly using Google CDN
- Load same stylesheet for front end and wp-admin
- How to remove all enqueued assets from the active theme?
- Not all my scripts are enqueueing
- JavaScript is not enqueuing
- browser showing connection was reset while accessing posts from local host
- Should we explicitely enqueue jQuery and our theme’s main stylesheet?
- wp_enqueue_style referencing parent theme
- include jquery plugin file not working
- Enqueueing Scripts/Styles mid-page
- add WordPress script to page conditionally by category
- load jquery in footer not working
- I want to set global directory locations for my CSS and JS locations. How?
- Fatal error: Call to undefined function wp_enqueue_media()
- javascript file is not enqueing
- Enqueueing Scripts and Styles to page template that has html
- Calling wp_localize_script in a different function
- Check for Twitter Bootstrap Loaded
- Stop a plugins js and css from loading on all pages and show up only where it is called
- wp_enqueue_scripts in a plugin’s class
- thickbox never gets called (weird behavior)
- What to include to use jQuery UI Auto Complete
- Filter enqueued styles and scripts
- wp_enqueue_script was called incorrectly. Scripts and styles
- Unqueue css file from specific page
- Modifying an enqueued script URL
- Enqueue registered dependencies only when necessary
- wp_enqueue_scripts action from a plugin overrides theme wp_enqueue_scripts no matter what the priority setting
- Trouble with wp_enqueue_script
- Can’t get jquery script to work
- Proper use of wp_localize_script?
- Prevent caching when using wp_enqueue_script?
- Should I be enqueueing styles/scripts once and then dequeueing them?
- List all non-admin enqueued files
- How to load default wordpress scripts
- Generating embed code for users to share
- How do I display the handle for all front-end enqueued scripts in plugin options page?
- css3-mediaqueries-js failing with child theme
- Registering / Enqueing Scripts Not Working
- Enqueueing Script to footer puts it at the very bottom
- See Scripts used by Page
- wp_script_is(‘enqueued’) true, but file not requested in HTML
- Why do WordPress adds the id=”handle-{js|css}” attribute to scripts and stylesheet?
- Dequeue/deregister scripts for everybody but the administrator
- comment-reply.js is not loading
- How can I specifically enqueue scripts for edit orders pages only