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.

My client has a site running the latest version of WordPress, with Thesis.

Currently, jQuery is being loaded in the footer, as the very last script to be loaded. I'm not sure what is causing jQuery to load - possibly Thesis, or something else.

We are adding a plugin, which has a script that loads. The script is being loaded in the footer. But it's being loaded BEFORE jQuery, so it fails.

The enqueue scripts line is this:

add_action('wp_enqueue_scripts', array($this, 'stb_enqueue_scripts'));

I edited it to be this:

$deps = array("jquery");
add_action('wp_enqueue_scripts', array($this, 'stb_enqueue_scripts', $deps));

But that didn't solve the problem - in fact, the script no longer loaded at all.

How can I make sure this script loads after jQuery?

Thank you!!

share|improve this question

1 Answer 1

Using wp_enqueue_script or wp_print_script function you can load your JS file after jQuery loaded. Usage Reference -

<?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>

The $dep argument (dependencies) should be an array or null or empty, and should not be used the way you did on your code. It will be on with wp_enqueue_script or wp_print_script function.

Your first used add_action reference is valid, but the second one is invalid.

On your stb_enqueue_scripts function, it should be -

function stb_enqueue_scripts()
{
    // third argument is the dependencies, should be array or boolean false
    // fifth argument = boolean true if loading the script at footer
    wp_enqueue_script( 'script-name', 'script_url', array('jquery'), '', true );
}
share|improve this answer

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.