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

WordPress WordPress Theme Development Building Out WordPress Navigation The wp_nav_menu Function

Catherine Millington
Catherine Millington
3,754 Points

What's wrong with my functions.php

I can't work out what's wrong here. The shortcut nav won't work in the 'coding a basic navigation' tutorial. I have made the changes that zac has but it won't work.

function wpt_theme_styles() {
    wp_enqueue_style( 'foundation_css', get_template_directory_uri() . '/css/foundation.css'
);
//wp_enqueue_style( 'normalize_css', get_template_directory_uri() . '/css/normalize.css');
wp_enqueue_style( 'googlefont_css', 'http://fonts.googleapis.com/css?family=Asap:400,700,400italic,700italic' );

wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );

}

add_action( 'wp_enqueue_scripts', 'wpt_theme_styles' );



function wpt_theme_js() {

    wp_enqueue_script( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', '', '', false );
    wp_enqueue_script( 'foundation_js', get_template_directory_uri() . '/js/foundation.min.js', array('jquery'), '', true );
    wp_enqueue_script( 'main_js', get_template_directory_uri() . '/js/app.js', array('jquery', 'foundation_js'), '', true);
}

add_action( 'wp_enqueue_scripts', 'wpt_theme_js' );

The errors on the console are as follows;

(index):118 GET http://localhost/localwp.com/assets/js/foundation.min.js (index):119 GET http://localhost/localwp.com/assets/js/app.js (index):117 GET http://localhost/localwp.com/assets/js/vendor/jquery.js (index):121 Uncaught TypeError: $ is not a function(anonymous function) @ (index):121 (index):117 GET http://localhost/localwp.com/wp-content/themes/img/icon-facebook.png?1398714906 404 (Not Found) (index):117 GET http://localhost/localwp.com/wp-content/themes/img/icon-email.png?1398715679 404 (Not Found) (index):117 GET http://localhost/localwp.com/wp-content/themes/img/icon-twitter.png?1398715010 404 (Not Found) (index):117 GET http://localhost/localwp.com/wp-content/themes/img/icon-vimeo.png?1398715539 404 (Not Found) (index):117 GET http://localhost/localwp.com/wp-content/themes/img/icon-flickr.png?1398714947 404 (Not Found) (index):117 GET http://localhost/localwp.com/wp-content/themes/img/icon-linkedin.png?1398715654 404 (Not Found) (index):117 GET http://localhost/localwp.com/wp-content/themes/img/icon-google.png?1398714980 404 (Not Found) (index):117 GET http://localhost/localwp.com/wp-content/themes/img/icon-youtube.png?1398715038 404 (Not Found) (index):117 GET http://localhost/localwp.com/wp-content/themes/img/icon-octocat.png?1398715632 404 (Not Found)

Andres Altuve
Andres Altuve
16,274 Points

Your functions.php looks fine, if you check the console errors, you will see that there are a lot of files that can´t be found, and I´m not sure but you should load jquery to your site and by looking at your functions.php you are not loading it anywhere, add it on on top of your wpt_theme_js() function.

Catherine Millington
Catherine Millington
3,754 Points

Thanks Andres. I've tried that but its still now working. Have I added it correctly?

function wpt_theme_styles() {
    wp_enqueue_style( 'foundation_css', get_template_directory_uri() . '/css/foundation.css');
/*wp_enqueue_style( 'normalize_css', get_template_directory_uri() . '/css/normalize.css');*/
wp_enqueue_style( 'googlefont_css', 'http://fonts.googleapis.com/css?family=Asap:400,700,400italic,700italic' );
wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );

}

add_action( 'wp_enqueue_scripts', 'wpt_theme_styles' );

function wpt_theme_js() {

    wp_enqueue_script( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', '', '', false );
    wp_enqueue_script( 'jquery', get_template_directory_uri() . '/js/jquery.js', '', '', false);
    wp_enqueue_script( 'foundation_js', get_template_directory_uri() . '/js/foundation.min.js', array('jquery'), '', true );
    wp_enqueue_script( 'main_js', get_template_directory_uri() . '/js/app.js', array('jquery', 'foundation_js'), '', true);
}

add_action( 'wp_enqueue_scripts', 'wpt_theme_js', 'jquery' );

Error messages:

http://localhost/localwp.com/assets/js/app.js Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/localwp.com/assets/js/vendor/jquery.js Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/localwp.com/assets/js/foundation.min.js Failed to load resource: the server responded with a status of 404 (Not Found) localhost/:121 Uncaught TypeError: $ is not a function http://localhost/localwp.com/wp-content/themes/img/icon-octocat.png?1398715632 Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/localwp.com/wp-content/themes/img/icon-vimeo.png?1398715539 Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/localwp.com/wp-content/themes/img/icon-youtube.png?1398715038 Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/localwp.com/wp-content/themes/img/icon-linkedin.png?1398715654 Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/localwp.com/wp-content/themes/img/icon-facebook.png?1398714906 Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/localwp.com/wp-content/themes/img/icon-twitter.png?1398715010 Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/localwp.com/wp-content/themes/img/icon-email.png?1398715679 Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/localwp.com/wp-content/themes/img/icon-flickr.png?1398714947 Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost/localwp.com/wp-content/themes/img/icon-google.png?1398714980 Failed to load resource: the server responded with a status of 404 (Not Found) (program):61 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.

It looks like its trying to get the foundation.min.js from localwp but i've been loading it through the themes/js? Why would that be do you think?

Catherine Millington
Catherine Millington
3,754 Points

I've figured it out. I hadn't updated the footer which was calling on loads of the files from different places which is why it was getting so confused. Thanks for your help!