WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is the JSFiddle http://jsfiddle.net/thornwalker/3LQjS/

I'm trying to get it to run on my wordpress blog and having no luck. My skill is novice at best, but up until now I've been able to muddle through.

This is the code I have in my functions.php (in my main theme, if I copy the functions.php to my child theme it won't run.)

function videoswitch() {
wp_enqueue_script('videoswitch', get_template_directory_uri() . '/js/videoswitch.js',
add_action('wp_enqueue_scripts', 'videoswitch');

Finally, here's the videoswitch.js


var directionsVar = '<video autoplay="" loop=""><source src="directionsVid.mp4" type="video/mp4"></video>';

var storyVar = '<video autoplay="" loop=""><source src="storyVid.mp4" type="video/mp4"></video>';

$("#directions").hover(function () {

$("#story").click(function () {

Any help would be greatly appreciated.

share|improve this question
The script file itself gets loaded? – kaiser Feb 4 '14 at 13:27
I honestly don't know how to check if it does. I see an error in inspect element that looks like it's trying to load the javascript from the parent theme and the child theme URLs all combined. – Thornwalker Feb 4 '14 at 13:30
get_template_directory_uri() always refers to the parent theme. Is this what you want? – toscho Feb 4 '14 at 13:34
Ah, no. videoswitch.js is in a subdirectory of the child theme. Should I be using get_stylesheet_uri() in that case? Since it's not a stylesheet I found that confusing. – Thornwalker Feb 4 '14 at 13:35
Check the page source with Chrome Developer Tools/FireBug/etc. and look for the file or any 404s. And you should use get_stylesheet_directory_uri(). – kaiser Feb 4 '14 at 13:40
up vote 0 down vote accepted

Use get_stylesheet_directory_uri() to get URLs for the child theme.

get_template_directory_uri() always refers to the parent theme.

If there is no parent theme, both functions will return the same result.

Note that both functions do not add a trailing slash, you have to do that in your code.

share|improve this answer

Your Answer


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.