No worries, we all started somewhere, and it’s not like I’m some WordPress master anyway. Yes, I did omit an opening bracket.
You should create a new file with the jQuery(document)… code in it and it should be a javascript file (has a .js extension). That can go anywhere, but it’s easy to keep organized if you just put it in your theme. I wouldn’t suggest putting it in the wp-e-commerce directory, as I believe that gets completely nuked when you upgrade.
Because WordPress is a templating system, meaning it renders pages dynamically based on content from the database and from multiple script files, you don’t add javascript in a <script>…</script> tag in your <head> like you would on a “normal” site. Functions.php is an excellent sandbox to paste in code until you get the hang of making one-time plugins for client sites.
What you’re doing, step by step, is “hooking” the function enqueue_my_listener onto the action wp_enqueue_scripts with the add_action call. When WordPress runs the code, do_action('wp_enqueue_scripts')
, all functions hooked that will be executed.
In the function itself, first you are registering your script file with WordPress.
The first argument ‘my-listener’ is arbitrarily named, but it’s helpful to name is something like the javascript file. If you were going to refer to it later (which you do in wp_enqueue_script), that’s what you’d refer to it by.
The second parameter is the path to the file, pretty self explanatory.
The third parameter is where you declare dependencies for your script. Meaning, this script will not be included until everything it is dependent on has been included as well. That way, you can be sure that the wpec js has already been included before you script is.
Then, you’re running wp_enqueue_script, which is actually what puts the <script src=”…”></script> into the generated web page (I’m generalizing here).
Make sense?