1

Following How to add a javascript snippet to the footer that requires jQuery I am trying to load jQuery before my script does stuff but it's not working.

This is it working when I include jQuery manually

This is it not working when I do it the right way.

In that previous question, the answerer says I should put my script material inside an if( wp_script_is( 'jquery', 'done' ) ) {, and I tried that too but the part within the if never gets executed.

5
  • 3
    Why not just hook everything to wp_enqueue_scripts and put it in separate javascript files if you're just going to wrap it in jQuery(document).ready(function($).. anyway? Commented May 31, 2013 at 17:11
  • 5
    Do you see jQuery in source at all when queueing? Also you should be using wp_enqueue_scripts hook rather than more generic wp_head.
    – Rarst
    Commented May 31, 2013 at 17:14
  • @Rarst TRhank you!! I saw that it loads after my code.. I should put wp_enqueue_script( 'jquery' ); outside of myscript_jquery() function. It's working now. :) Commented May 31, 2013 at 17:40
  • @AndrewBartel Part of my script has to be dynamically made, using variables from my plugin. (I'm looking into how to achieve my goal without that, but this is still a valid approach, no?) Commented May 31, 2013 at 17:40
  • 2
    use wp_localize_script to pass data from php to javascript, no need to print it directly to the page yourself.
    – Milo
    Commented May 31, 2013 at 18:03

0

Your Answer

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