0

I'm trying to create a custom WP theme with foundation but the menu never seem to work.

After some time I realized that my scripts loaded (I see them in the header - firebug) but not activating. Weird.

This is my functions.php for loading the scripts. Pretty simple:

function enqueue_test_scripts() {

/* Original Foundation scripts and styles

<script src="js/vendor/jquery.js"></script>
<script src="js/vendor/what-input.js"></script>
<script src="js/vendor/foundation.js"></script>
<script src="js/app.js"></script>

*/

wp_enqueue_style('style-css', get_template_directory_uri().'/css/foundation.min.css');

wp_deregister_script('jquery');
wp_enqueue_script('jquery', get_template_directory_uri().'/js/vendor/jquery.js', false);
wp_enqueue_script('app', get_stylesheet_directory_uri().'/js/app.js', true);
wp_enqueue_script('what-input', get_template_directory_uri().'/js/vendor/what-input.js');
wp_enqueue_script('foundation', get_template_directory_uri().'/js/vendor/foundation.js',true);

}

add_action( 'wp_enqueue_scripts', 'enqueue_test_scripts',0);

Just to make sure I tested a quick and simple html menu in index.html and it works. I then dropped it in below the header in the wordpress theme php file and now it's just static - no dropdown effects or anything.

So the scripts are there, they are loaded, but not doing activating.

My only conclusion is that they are in conflict with something but I have no idea what.

Could it have something to do with using jQuery( instead of $(...?

Something else?

  • 1
    try to add your scripts in the same order than the commented line. js/app.js is the last (in commented line) not when you use wp_enqueue_script. – Benoti Nov 10 '16 at 14:53
  • 1
    Are there errors in browser console? Sounds like broken JS. Also overriding core's jQuery is considered a bad practice in WP. – Rarst Nov 10 '16 at 16:52
0

Benoti

Yes, that was it! Seems app.js needs to be the last item loaded. Here is the final function with a couple of changes for anyone interested:

function foundation_scripts() {

wp_deregister_script('jquery');

wp_register_script('jquery', get_template_directory_uri().'/js/vendor/jquery.js', false);
wp_enqueue_script('jquery');
wp_enqueue_script('foundation-js', get_template_directory_uri().'/js/vendor/foundation.js', array('jquery'), false, true);
wp_enqueue_script('what-input', get_template_directory_uri().'/js/vendor/what-input.js', false, true);
wp_enqueue_script('app', get_template_directory_uri().'/js/app.js', array('jquery', 'foundation-js'), false, true); }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.