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 trial
ian izaguirre
3,220 PointsI need help getting my JavaScript file to work on wordpress through child theme?
Hi , So I looked at the video on team tree house about link a JS file to my wordpress theme, and was a little confused since its in refrence to including a sliders JS . BUT This is my interpretation please let me know if it is correct. So I have the file called myscript.js in my child theme now I want to "activate it for use" so in my child themes functions php file I put the following :
```// Function to load theme javascript function theme_javascript() {
// Register slider script
wp_register_script('myscript',get_template_directory_uri().'js/jquery.myscript.js',array('jquery'),'1.0');
// Enqueue theme script
wp_enqueue_script('myscript',get_template_directory_uri().'js/theme.js',array('jquery','myscript'),'1.0');
}```
Is this all ? is the correct? Thank you
1 Answer
Jose Morales-Mendizabal
19,175 PointsWhen Enqueuing your script, you do not need to pass in all those parameters to the wp_enqueue_script() function. Rather, pass it the handle you defined when your registered your script, which in your case I believe it is 'myscript'.
so enqueue it as such:
wp_enqueue_script('myscript');
If this doesnt work make sure you have the correct wordpress hook of wp_footer() in your footer so it can be linked on your footer after the </body> and thus load after the DOM has finished loading.