Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBob Sutherton
20,160 PointsLinking Javascript in WordPress
I am following along with the video and trying to copy everything. At this point, I believe I have done everything the same as Zac Gordon has done. However, when he views the page source to see the the "theme.js is properly loading" it shows up. When I look at my page source, I do not see it.
// Load the Theme JS
function theme_js() {
wp_register_script('flexslider', get_template_directory_uri() . '/js/flexslider.js', array('jquery', '', true) );
if(is_page('home')){
wp_enqueue_script('flexslider');
}
wp_enqueue_script('theme_js', get_template_directory_uri() . '/js/theme.js', array('jquery', '', true) );
}
add_action('wp_enqueue_scripts', 'theme_js');
Can you see anything wrong based on the code I have posted?
3 Answers
Derk van der Heide
11,472 PointsFound it!
It's in this line:
wp_enqueue_script('theme_js', get_template_directory_uri() . '/js/theme.js', array('jquery', '', true) );
The ) is in the wrong place. It should be: array('jquery'), '',true);
but you typed: array('jquery',true));
You also made the same error at the line were you register flexslider.js
Bob Sutherton
20,160 PointsNevermind posting the code line, Derk. I got it to work. Those dang )'s are giving me a hard time! Ha. Anyway, thanks for your help.
Derk van der Heide
11,472 PointsI don't think there is anything wrong with your code. I'm following along as well and I had the same problem.
I noticed when I went to the homepage I saw this error in the url:
Notice: get_bloginfo was called with an argument that is deprecated since version 2.2! The siteurl option is deprecated for the family of bloginfo() functions. Use the url option instead. in /var/www/html/wordpress/wp-includes/functions.php on line 3318
So go to header.php and change the bloginfo("siteurl") to bloginfo("url") and everything should work I think!
Edit: Just realised you had a problem with home.js loading, not flexslider.js :p But leaving this here in case it helps.
Bob Sutherton
20,160 PointsInteresting Derk. I don't have a bloginfo('siteurl') at all on my header.php page. I have one for 'name' for the page title but not relating to javascript. I never noticed him putting that in the linking Javascript video. Could this be what is causing my issue?
Derk van der Heide
11,472 PointsAh it's probably not related, I think it's something for a later video. I got confused there for a second and forgot you had problems with home.js loading, not flexslider.js.
Bob Sutherton
20,160 PointsBob Sutherton
20,160 PointsThanks Derk. When I tried to implement your suggestion the page threw an error. Could you write out the code correction and let me copy and paste it in?