Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress

Simon Tucker
Simon Tucker
9,113 Points

adding jquery js files to my functions.php

I am using slick nav js file in my wordpress theme. I cant seem to get this working as it can't find the correct dir path.

I know it works on my html testing page fine but having real trouble with the functions.php

add_action('wp_enqueue_scripts', 'wpt_theme_styles'); 
function wpt_theme_js() {

    wp_enqueue_script( 'modernizr_js','https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js'); 

    wp_enqueue_script( 'jquery_slicknav', get_template_directory_uri().'/js/jquery.slicknav.min.js', array('jquery'), '', true ); 

    wp_enqueue_script( 'slick', get_template_directory_uri().'/js/slick.nav.js', array('jquery', 'jquery_slicknav'), '', true );
    }
add_action('wp_enqueue_script', 'wpt_theme_js'); 
?>

1 Answer

Tobias Helmrich
Tobias Helmrich
31,601 Points

Hey Simon,

the action hook is called wp_enqueue_scripts but you're writing wp_enqueue_script . Try adding the "s" in the end and see if that works.

I hope that helps! :)

Simon Tucker
Simon Tucker
9,113 Points

Hi there, thanks for the quick response but It's still not working correctly. What is happening is slick nav menus are displaying on full screen but when I resize to mobile view the menu disappears. I know that the css is right so I'm not sure why it's not linking properly in functions.

I even try putting the js scripts in header.php to test and still nothing.

Simon Tucker
Simon Tucker
9,113 Points

Thanks for that Tobias It was not only adding an s but I completely forgot that when a js file is in wordpress it doesn't like $ on it's own, so needed to wrap it in a jquery function like so:

jQuery(document).ready(function($){
$('#menu').slicknav({
label: '',
duration: 600,

  });

});