Trying to do the right thing here, and tying myself in a knot! So, in my header.php before wp_admin
, I have:
wp_enqueue_script('commonfunctions', child_template_directory . '/script/commonfunctions.js', array('jquery', 'jquery-ui-draggable'), '1.0', true);
which works. Basically, I have a custom js file which needs jquery and jqueryui as dependencies. I since took ‘jquery’ out as it seems to be loaded twice irrespectively. I also had a function hooked into ‘init’ in functions.php, but that didn’t seem to have any advantage?
I want to include the validate script from CDN as this will also be a dependency of my custom script. I thought I would register the script like so:
wp_register_script('validate', 'http://ajax.microsoft.com/ajax/jQuery.Validate/1.6/jQuery.Validate.min.js', true);
and then add ‘validate’ to the dependencies array in enqueue, like so:
wp_enqueue_script('commonfunctions', child_template_directory . '/script/commonfunctions.js', array('jquery', 'jquery-ui-draggable', 'validate'), '1.0', true);
in that order, as jquery is also a dependency of validate. Phew! That doesn’t work, I’m obviously misunderstanding something – please help me uncurl what I’m trying to do here…
I think you should just enqueue the script as well (for your validate script). I would wrap it around one whole function as well to avoid issue #11526: calling out
Thus all together:
Sorry, i haven’t tested this yet. So i may be off.
This should not happen and is likely cause by some other (poor) code active.
You have wrong
true
invalidate
registration – after source comes dependencies array andtrue
is meaningless there.Otherwise this seems fine in general. Works from quick test. Could you describe more precisely what exactly and how “doesn’t work”?