Understand wp_enqueue’s dependencies parameter
You need to ensure the other script depends on jQuery being ready before it loads. Checking the wp_enqueue usage example:
<?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>
It is $deps
(dependencies) that we can utilise for this purpose.
Properly enqueue the second script, and leverage that parameter
Secondly you should use the enqueue function to conditionally load the second script:
if ( is_page_template( array('template-name.php'))){
wp_register_script('xxx', '/path/to/script/xxx.js', array('jquery'),'1.0',true);
wp_enqueue_script('xxx');
}
Notice the array('jquery')
which stops this script loading before jQuery is ready.
Related Posts:
- AJAX handler throws 400 (Bad request) – why?
- ajax live search for post title
- Apply jquery script to only woocommerce product pages and categories
- Replacing select2 in admin backend for all selects
- How to save Uploaded image in custom option panel?
- jQuery plugin function is not a function
- Display a function using AJAX
- Enqueuing Script in functions.php vs on the page
- Unable to get_the_content(); of a post in WordPress via AJAX
- Add external js file to footer with id
- Ajaxing function in widget class
- How to load some jquery code to make validation in the theme customizer?
- woocommerce target button with class after ajax update
- Move jQuery and Migrate to footer?
- jquery won’t load in footer
- WordPress doesn’t Load JQuery Now? Do I need to enqueue JQuery also?
- Woocommerce checkout field maxlength, make input number field only (postcode)
- Replace menu links with # and add name to its li
- Loading CDN that requires jQuery in WordPress
- is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript
- Right way to update widget on dynamic new input field
- How to load jQuery in the footer – nothing works for me
- Not sure if enqueuing js scripts properly
- Wp_query function to search from product_title ‘OR’ product tags name
- Allow Post Author to be 0 on Update
- Trouble with adding a wp_enqueue_script on wordpress
- WP Ajax Function Always Returning undefined
- Scripts not appending to element in AJAX call – why?
- How to search using ajax for exact phrase or words in an input field?
- how to en-queue jQuery to load before the tag
- Jquery implementation not working on page reload
- I can’t enqueue my scripts – They literally aren’t being added to my site
- Attempt to change jQuery version caused White Screen of Death
- PHP mixed with some JS code to update WordPress theme settings
- Load jquery only for certain pages in the backend
- Change CSS for logged in users
- Always the Latest google jQuery instead of default WordPress jQuery
- Add a jQuery Function
- jQuery does not work
- using jQuery on only one page
- Can’t call Javascript function – scope?
- Changing parent element’s class or style
- Enqueuing latest version of jQuery into a child theme returns a blank screen
- echo custom fields with AJAX
- Adding jQuery datepicker to Custom Post Type Metabox [closed]
- In jquery use php variable to execute an enqueued jquery file
- Run a jquery script on on a certain template page
- Add php code to wp_print_scripts?
- How can i unload effect.min.js file?
- wp_enqueue_script | Help me figure out what is causing jQuery is not defined
- Where is this JQuery coming from?
- This code works, but the way I integrated it is breaking the media uploader. How can I integrate it properly?
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- How to load jQuery in TOP of wp_footer?
- Passing Jquery value to WordPress function
- WordPress can’t get jquery/unslider to work
- Add loggedout class on body using a function or JS
- Are innerHTML elements visible to jQuery functions?
- Include Jquery libraries in wordpress theme?
- Why a SlideShow (made using JQuery FlexSlider) can’t work if I load it form functions.php but work if I load it from my footer.php file? [closed]
- get content from page through AJAX
- Creating multiple category drop down
- How to setup a popup registeration page in wordpress with function.php
- colorbox not loading in
- How to add php within jquery
- Help with IF has focus then… statment
- Get URLs for AJAX Filter Checkboxes WordPress
- wp_set_object_term via js btn frontend
- Populate Product Regular Price with a calculated ACF Field Value
- Hide ‘add to cart’ when certain value in dropdown is selected
- Ajax Form Issues using Lightsail (AWS)
- What is the earliest Hook a Script can use?
- WordPress does not load jQuery
- post value to function with Ajax and jQuery
- Images with overlay
- How to use `foreach()` in ajax call
- How To Display Author Popup on Entry Meta (Genesis Framework)?
- Multiple Notifications SetInterval
- How do i create a search option for pdf’s only
- WordPress Ajaxifying not working properly
- Execute jQuery with custom event listener after successfully add an item to the cart
- Load scripts into an AJAX div
- Load scripts into an AJAX div
- True parameter but jquery register in header and not in the footer with wp_register_script
- Automatic add space if user enters number(any digit)
- WordPress Jquery+scripts enqueue issue
- Moving CDN jQuery to footer does not work?
- Adding a jQuery rotator function
- Why are some custom javascript files working but some are not
- WordPress Javascript Widget jQuery Dependency Issue
- jQuery HoverIntent is not a function
- How to use different jquery function of idangero swiper dependant on page template?
- Ajax call does not work for this custom code
- How do I get my nav menu to show sub pages?
- Having problems loading Jquery in functions.php
- Owl Carousel and WordPress Integration Via WP_Enqueue
- AJAX values converted to PHP Variables?
- Animated Accordion [closed]
- iOS and ajaxComplete
- Paged Single Post doesn’t redirect to the main url after Removing Pagination