I’m developing a WordPress theme and can’t get JavaScript to run. When I view the source code the scripts have loaded and the file paths are correct.
Here is the functions.php code that loads the scripts:
function theme_js() {
// Conditional scripts
global $wp_scripts;
wp_register_script( 'html5_shiv', 'https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js',
'', '', false );
wp_register_script( 'respond_js', 'https://oss.maxcdn.com/respond/1.4.2/respond.min.js',
'', '', false );
$wp_scripts->add_data( 'html5_shiv', 'conditional', 'lt IE 9');
$wp_scripts->add_data( 'respond_js', 'conditional', 'lt IE 9');
// Footer scripts
wp_enqueue_script( 'bootstrap_js', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js',
array('jquery'), null, true );
wp_enqueue_script( 'color_js', get_template_directory_uri() . '/bootstrap/js/jquery.color.js',
array('jquery'), null, true );
wp_enqueue_script( 'header_js', get_template_directory_uri() . '/bootstrap/js/header.js',
array('jquery'), null, true );
wp_enqueue_script( 'rollover_js', get_template_directory_uri() . '/bootstrap/js/rollover.js',
array('jquery'), null, true );
}
add_action ( 'wp_enqueue_scripts', 'theme_js' );
Can anybody tell me why they won’t run?
For reference – header.js:
$(window).scroll(function () {
//After scrolling 300px from the top...
if ($(window).scrollTop() >= 300) {
$(".navbar").stop().animate({backgroundColor: "#1e3b4e"}, 600);
$(".navbar-nav > li > a").css("color", "#ffffff");
$("#logo").attr("src", "img/logo.png");
//Otherwise remove inline styles and thereby revert to original stying
} else {
$(".navbar").stop().animate({backgroundColor: "rgb(255, 255, 255, 1)"}, 400);
$(".navbar-nav > li > a").css("color", "#1e3b4e");
$("#logo").attr("src", "img/newlogo.png");
}
});