I’m trying to run Jquery after the page has loaded to modify some elements on the page. It seems like if I use document.ready, not all of the X theme stuff has loaded. Right now I have a 4 second timeout to ensure that everything has loaded, but there has to be a more elegant way to handle this. Any suggestions?
Hello @brettgustafson,
Thanks for asking.
What you are looking for falls outside the scope of support we offer. I suggest you to please take a look at following resources for us help.
https://stackoverflow.com/questions/1012140/delaying-a-jquery-script-until-everything-else-has-loaded
https://getflywheel.com/layout/how-to-load-javascript-in-wordpress/
https://developer.wordpress.org/reference/functions/wp_enqueue_script/
Thanks for understanding.
But just to understand, is that something that I’d have to use wp_enqueue_script for and not the per page JS custimization?
Thanks!
Hi there,
Yes, that is right. Basically, what you can try doing is to create a js file then enqueue the file in the footer.
Here is another reference:
Basically, you will use wp_enqueue_script
to load the script in the footer then set the priority parameter of add_action
to a bigger value so that the script will be loaded later than the other scripts.
You may also specify the JS file to only load on specific page but using the is_page() conditional tag.
Hope this helps you get started.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.