To accomplish this, wrap wp_enqueue_script in a function and run it through the action hook wp_enqueue_scripts while using the ‘priority’ parameter available in add_action to set the load order.
function these_go_first() {
wp_enqueue_script('first_script', '[path to file]/first.js', array('jquery'), '1.0' );
}
function these_go_first() {
wp_enqueue_script('after_script', '[path to file]/after.js', array('jquery', 'first_script'), '1.0' );
}
add_action('wp_enqueue_scripts', 'these_go_first', 1);
add_action('wp_enqueue_scripts', 'these_go_after', 2);
wp_enqueue_script can also define script dependencies as well. This is why I added ‘first_script’ which I had already defined in the function just before, to the dependencies array in the second function.
Related Posts:
- Move WordPress native javascript to bottom of page?
- RequireJS in custom theme. Working Example
- How to get a jQuery script to run on a page?
- Including javascript for a shortcode
- Asynchronous Javascript Loaders
- wp_enqueuescript won’t load in footer even with true value set?
- How wp_enqueue_script works?
- How do I get my page to load the jQuery UI Effects library?
- Script won’t execute in the media manager
- How to properly add Bootstrap and JQuery Javascripts?
- Enqueuing javascript files
- Searching multiple tags and adding jQuery dependant script onto page template?
- Plugin Scripts no loading on options page
- How to enque js script in footer that are not in .js file?
- Loading scripts on a single page plants the script in the footer
- Using WP functions inside javascript
- Including Older Version of jQuery for IE7/IE8
- How To Include JavaScript Files Only In Single Posts?
- How to make JQuery load on top of head tag before everything
- JavaScript code do not works on online server
- Bootstrap with separate js File
- How to add JS snippet before closing tag?
- Enqueue javascript that inserts custom php widget into jQuery-constructed div
- javascript not loading in wordpress
- bootstrap-slider.js by seiyria not working in wordpress
- Why does my JavaScript code receive a “No ‘Access-Control-Allow-Origin’ header is present on the requested resource” error, while Postman does not?
- Javascript Runtime error: $ is undefined
- Javascript TypeError: Cannot read property ‘indexOf’ of undefined
- How to read data From *.CSV file using javascript?
- How to call a webservice method from an html page [javascript] with out refresh the page
- How can I remove all CSS classes using jQuery/JavaScript?
- Enqueue core jQuery in the footer?
- How to correctly include jquery-ui effects on wordpress
- I want to enqueue a .js file to my child theme
- Concatenate and minify dependencies for enqueued JavaScript files
- tinymce is not defined when not using wp_editor
- Adding jquery and thickbox to WordPress theme
- jQuery UI Datepicker not working
- Best Way to Include Scripts on a Specific Template Page
- chosen jquery library not loading – is not a function error
- Unable to run jQuery script in my template file
- Enqueue jQuery in WordPress
- Enqueuing Script in functions.php vs on the page
- Simple jQuery Click Not Working, though console log recognizes the function [closed]
- How to add unique image class to WordPress
- Dropzonejs with WPCF7 [closed]
- wp_ajax() question.. not using wp_enqueue_script?
- Jquery conflict
- enqueue the scripts
- WP Admin missing icons, numerous JavaScript errors, but only when SCRIPT_DEBUG is false
- WordPress loads Jquery Automatically – is my idea correct to add it to the footer?
- Problem in loading javascript in footer
- wpColorPicker: How update colors on input value update?
- Enqueue WordPress jQuery after it’s been deregistered by a plugin
- How to embed JS data viz in a simple WordPress website
- WooCommerce Ajax Cart Update Stopped Working
- Rhyzz Repeatable-fields javascript in php and wordpress
- how to en-queue jQuery to load before the tag
- Enque Javascript in Footer?
- Plugins loading multiple copies of JQuery
- Cannot enqueue jQuery correctly using Google CDN
- Yoast SEO breaking media upload
- How to return multiple arguments from AJAX callback function
- JS news ticker is not working on home page but working on other pages. How to solve this?
- How register library to use jquery correct
- WP Customizer compare and set a value via javascript
- “JQMIGRATE: Migrate is Installed” How do I find the problem code? [duplicate]
- Referrer URL with jQuery or Javascript – Cache & Referrer URL Issue
- Using Foundation 5 in WordPress Administration Area
- Ajax Validation for reCaptcha
- Using jquery and javascript in WordPress
- Run a jquery script on on a certain template page
- Run JS function when JQ enqueued
- Can’t delete the default jQuery in the theme
- How to load jQuery in TOP of wp_footer?
- oEmbed Video in Modal
- Include Jquery libraries in wordpress theme?
- AJAX Success Function using JS substr() fails in WP 4.1 vs 4.0
- wordpress before or after javascript problem
- Ajax page load in wordpress the right way?
- I am trying to Implement a Code that is Working in my previous page but not working in WordPress for some reason
- How to use $ with externally loaded javascript
- Getting click on item to open closest relevant element (popup) with jQuery
- Show and hide element when URL contains certain section of text?
- Customizer add query to preview URL
- jQuery Plugin Uncaught TypeError: jQuery(…).slider is not a function
- Notify user we would like them to clear their cookie. Provide a working button to clear cookies for user
- Call full image url instead of stylsheet directory url in JS for Infinite Scroll Function
- How to blur the_post_thumbnail() via blur.js (jquery)?
- Custom Javascript not working? [closed]
- How to get this jQuary script working?
- Youtube Iframe Api play one video at a time
- Disable drag metaboxes, create many functions using js not to work!
- Scripts only working on home page
- Add jQuery function to media button
- TypeError: $ is not a function Error using parallax effect in WordPress Template [duplicate]
- jQuery append only works if I select html in admin section [closed]
- Javascript Loading Effect to URLs
- Use WordPress Built In Jquery
- Making the Google Maps API non readable