1

I am trying to add my custom scripts to my project but can seem to get them to load. I've never had this issue and am stumped. This is what I have in my functions.php:

function ex_scripts() {
    wp_enqueue_script( 'jquery' );
    wp_enqueue_script( 'backgroundJS', get_template_directory_uri() . '/js/background.js', array('jquery'), '1.0.0', true );
    wp_enqueue_script( 'superJS' , get_template_directory_uri() . '/js/supersized.core.3.2.1.js', array('jquery'), '1.0.0', true);
}

add_action( 'wp_enqueue_scripts', 'ex_scripts' );

I know the ex_scripts function is running. I added a echo "hello"; die(); statement to the top of the function and it worked. I also know the js filepaths are correct and that they are accessible. jQuery will load both with or without its enqueue script (because it's listed as a dependency of the lower two), but my custom scripts aren't being added.

  • 2
    are you using a child theme? does your theme call wp_footer? – Milo Oct 21 '13 at 20:04
  • Where is this code located? What file? – s_ha_dum Oct 21 '13 at 20:12
-1

Grab this.

add_action('wp_enqueue_scripts', 'my_custom_scripts', 999);
function my_custom_scripts() {
    wp_register_script('backgroundJS', get_stylesheet_directory_uri() . '/js/background.js', array('jquery'), '', true );
    wp_register_script('superJS' , get_template_directory_uri() . '/js/supersized.core.3.2.1.js', array('jquery'), '1.0.0', true);
    wp_enqueue_script('backgroundJS');
    wp_enqueue_script('superJS');
}

I'm using this and it has no problems for me

|improve this answer|||||
  • 1
    please explain how this is different and why. – Milo Oct 21 '13 at 22:44
  • It's good for later usage (if it's needed). otherwise it's same – Lukas J. Oct 22 '13 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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