When I put this code right above the closing of my body tag it works, but when I try to enqueue it, it breaks. I’m thinking maybe jQuery isn’t getting called? The snippet is from here
FUNCTIONS.PHP
add_action( 'wp_enqueue_scripts', 'scroll_port' );
function scroll_port() {
wp_register_script( 'scrolling', get_template_directory_uri() . '/js/scroll.js', array('jquery'), '', true );
wp_enqueue_script('scrolling');
}
SCROLL.JS
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^//,'') == this.pathname.replace(/^//,'')
|| location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});`
On your SCROLL.JS file, add the line before anything else,
And after everything else
This block will load you code after jQuery is loaded, and will avoid the errors.