Thanks Tom
For anyone who is interested in this thread, here is the full snippet to run smooth scroll from your own functionality plugin:
Note: this only works to smooth scroll to an anchor on the same page. It does not work if your anchor is on another page.
//////////////////// GP SMOOTH SCROLL ////////////////////////////////
add_action( 'wp_footer', 'tu_add_script' );
function tu_add_script() { ?>
<script>
jQuery(function($) {
$(document).on('click', 'a[href*="#"]:not([href="#"])', function(e) {
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) {
e.preventDefault();
$('html,body').animate({
scrollTop: target.offset().top
}, 500);
}
}
});
});
</script>
<?php }
//////////////////// END GP SMOOTH SCROLL ///////////////////////////////
Kind Regards
Max