I’ve been working on building a theme for the past couple days now, and I’ve run into a wall. While I originally included foundation.js as an enqueued script, I couldn’t remember why I had added it. Today, when I tried removing it (to improve page-load speed) from my functions.php file, it messed up all of my jQuery plugins.
After some researching, I discovered that Foundation already includes jQuery, so I was loading two instances of it at a time (I also loaded from the theme’s js folder). So, now that I’ve removed foundation, my custom.js file commands don’t work unless I prepend ‘jQuery’ instead of the simpler ‘$’.
I think there’s some part of my WordPress install that I made bug out, even if I keep the ‘Foundation’ name reference with the jQuery file earlier called, the theme works. It’s like it has to have that ‘Foundation’ name.
Below I’ve included both my script calls, as well as my custom js file, in hopes that someone will be able to aid me in diagnosing this problem.
Links:
-Chrome Console Error Message
-jQuery & Plugins shown loading in Chrome Console
SCRIPT CALLS:
function register_js() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_deregister_script('foundation');
wp_register_script('jquery', get_template_directory_uri() . '/js/libraries/jquery-1.7.1.min.js');
wp_register_script('jquery-ui', get_template_directory_uri() . '/js/libraries/jquery-ui-1.8.16.min.js', 'jquery');
wp_register_script('superfish', get_template_directory_uri() . '/js/plugins/jquery.superfish.js', 'jquery');
wp_register_script('supersubs', get_template_directory_uri() . '/js/plugins/jquery.supersubs.js', 'jquery');
//wp_register_script('foundation', get_template_directory_uri() . '/js/plugins/jquery.foundation.js', 'jquery');
wp_register_script('custom', get_template_directory_uri() . '/js/custom.js', array('jquery','jquery-ui') );
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui');
wp_enqueue_script('superfish');
wp_enqueue_script('supersubs');
//wp_enqueue_script('foundation');
wp_enqueue_script('custom');
}
}
add_action('init', 'register_js');
CUSTOM JS FILE:
$(document).ready(function() {
/* Menu - Superfish */
$('ul.menu').supersubs({
minWidth: 11,
maxWidth: 30,
extraWidth: 1
}).superfish({
hoverClass: "sfHover",
speed: 'fast',
dropShadows: false,
delay: 0,
autoArrows: false,
animation: {height:'show',opacity:'show'}
});
/* Blog Tabs */
$('#tab_controls').tabs({ fx: [ {opacity:'toggle', duration:'normal'},{opacity:'toggle', duration:'slow'}] });
});