I had the following jQuery script on a static HTML page and it worked fine. However, when I enqueue it into WordPress it doesn't work.
Here is the JS file.
$(window).scroll(function()
if ($(".navbar").offset().top > 50) {
$(".navbar-fixed-top").addClass("top-nav-collapse");
} else {
$(".navbar-fixed-top").removeClass("top-nav-collapse");
}
)};
And here is the functions.php
function hat_rack_media_scripts() {
//THEME CUSTOM STYLES AND SCRIPTS
wp_enqueue_style( 'hat-rack-media-style', get_stylesheet_uri() );
wp_register_script( 'theme-script', get_template_directory_uri() . '/js/script.js', array('jquery'), '1', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'hat_rack_media_scripts' );
I feel like i included the file correctly, it is mapped to the right location, and it worked just fine in a static html page.
Thanks.