Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have some scripts that I'm enqueueing like this:

wp_enqueue_script("jquery");
wp_enqueue_script("myscript" , get_template_directory_uri()."/js/myscript.js", Array('myscript'), " ");

I want to enqueue them in the footer, which means I should use the last parameter of wp_enqueue_script(), but I don't always want to pass the other params.

wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer);

How do I get to $in_footer without messing up the default params in between it and $handle? Can I just put empty strings for each?

share|improve this question
add comment

1 Answer

Try passing array() for $deps, and NULL for $ver:

wp_enqueue_script( $handle, $src, array(), NULL, $in_footer);

Or, using your function call:

wp_enqueue_script("myscript" , get_template_directory_uri()."/js/myscript.js", array(), NULL, true );

By the way, passing the script itself as a dependency to itself will probably make something blow up.

Note also: if your script depends on jQuery, just pass jQuery as a dependency, instead of enqueueing it separately:

wp_enqueue_script("myscript" , get_template_directory_uri()."/js/myscript.js", array( 'jquery' ), NULL, true );
share|improve this answer
    
Thanks--didn't actually mean to put myscript as a dependancy of itself--I was just simplifying the longer scripts there and didnt' notice I gave it the same name. –  brentonstrine Jan 22 '13 at 19:44
1  
Related question, if you care to follow up: wordpress.stackexchange.com/questions/82668/… –  brentonstrine Jan 22 '13 at 19:49
    
Actually--one question. You put the second parameter ($src) in there. But what if I already registered the script and don't want the source again? –  brentonstrine Jan 22 '13 at 20:36
    
If you already registered the script, then all of the parameters would go in your wp_register_script() call, and your wp_enqueue_script() call would simply include the script name: wp_enqueue_script( 'myscript' ). –  Chip Bennett Jan 22 '13 at 22:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.