1

I know that there are several posts on this here, but having gone through a ton of them, I am still having problems. So - up front apologies on adding another question on something that seems so straightforward but I'm new to this and stuck!

That being said - I have soundclick.js. It lives in my theme's js folder. It works pasted straight into the header - but i need it in my functions.php file like all the other good little javascripts.

function wpana_js() {

  wp_register_script('soundclick', get_template_directory_uri() . '/js/soundclick.js', array(), '0', false);
  wp_enqueue_script('soundclick');
} 

add_action('wp_enqueue_scripts', 'wpana_js');

Code goes in - javascript shows up in the page source, but then my calls to the javascript to get these sounds to play on a user click don't work anymore. (the calls worked just dandy when the javascript was pasted directly into the header)

Am i missing something obvious on getting the javascript back into working status? Thanks!

update i fixed the problem - apparently i was queuing correctly, but my problem lay in the js file itself. there was a basic problem with how i made the file. so it was showing up but not working. thanks all for taking a look :)

1
  • So let me see if I am understanding this correctly, the javascript is loading into the browser, but it is not working the script itself? Commented Jun 19, 2014 at 20:24

1 Answer 1

2

I would inspect the order in which your scripts are being loaded when

  • it works by pasting it directly into the header, versus
  • it's loaded via wp_enqueue_script() as you've done in functions.php

Is this library getting loaded after your JavaScript code that attempts to use it? Is soundclick.js a jQuery plugin?

If you need to load some scripts after others, ensure you define the dependent scripts in the array parameter like so (for example, if this script requires jQuery)

wp_register_script('soundclick', get_template_directory_uri() . '/js/soundclick.js', array('jquery'), '0', false);
Sign up to request clarification or add additional context in comments.

1 Comment

I was suspecting this as well but was trying to make sure the script was loading into the browser first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.