0

I have a script in my custom meta-boxes and wish to use jQuery, the problem is that the admin page loads my script before it loads jQuery, rendering my script useless, when I inspect the page it looks like this:

jQuery(document).ready(function($) {
  // use $
});

<!DOCTYPE html>

and then the rest of the document loads, with header and all that sweet jazz. Is there anyway I can get my <script>jquery here</script> load AFTER my jQuery gets loaded?

2
  • How is it happening? I mean, as long as jQuery is included before your script, it cannot be execute before it. Commented Feb 11, 2016 at 19:10
  • Im not sure why, Cant find where it puts the jQuery in queue Commented Feb 11, 2016 at 19:16

2 Answers 2

1

you have to insert your script into this way:

function load_custom_scripts()
{    
  wp_enqueue_script('custom_script', 'COMPLETE_PATH_TO_YOUR_SCRIPT');
}

do_action ( 'admin_enqueue_scripts', 'load_custom_scripts' );

I suggest you to put all of your custom scripts in a separate JS file and then load to the WP.

Sign up to request clarification or add additional context in comments.

Comments

0

Right, you cannot use jQuery until it has loaded..

But you can use plain JS:

window.addEventListener('load', function() {
 // $ should be available
}, false);

1 Comment

The loaded script is outside of the <!DOCTYPE html> element meaning the page rendered contains invalid markup so this would not help...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.