Loading jQuery and jQuery plugin script files correctly

This question already has an answer here:

  • How is it possible that the function of the test page works, but it does not go live?

    2 answers

Solutions Collecting From Web of "Loading jQuery and jQuery plugin script files correctly"

Add the jquery script as a dependency for your jquery-ticker.js and site.js files within the wp_enqueue_script function.


function bbc_frontend_script() {
wp_enqueue_script('ticker', plugins_url("/js/jquery-ticker.js", __FILE__), array( 'jquery' ) );
wp_enqueue_script('sitejs', plugins_url("/js/site.js", __FILE__), array( 'jquery', 'ticker' ) );
add_action( 'wp_enqueue_scripts', 'bbc_frontend_script' );

You also don’t have to enqueue jquery separately if you define it as a dependency.

Added missing ) at end of enqueue statements.

Check your examples. You are using plugins_url, but on your other example you say they are in the template directory.

Where are these js files actually located?

You need to register the scripts but also define them to the jQuery library e.g.

  wp_register_script('ticker', plugins_url("/js/jquery-ticker.js", array('jquery'), '1.3', true );

The array registers it after jQuery is loaded and the true is to set it to register in wp_footer and not wp_head