Created
May 3, 2020 18:51
-
-
Save vfontjr/c0d69fbb712f603ba1ed83732da50ffb to your computer and use it in GitHub Desktop.
Source code for https://victorfont.com/genesis-html5-go-to-top-source-code/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Copy this to the bottom of functions.php | |
//* Create a shortcode to display our custom Go to top link | |
add_shortcode('footer_custombacktotop', 'set_footer_custombacktotop'); | |
function set_footer_custombacktotop($atts) { | |
return '<a href="#" class="top">Return to top of page</a>'; | |
} | |
//* Add smooth scrolling for any link having the class of "top" | |
add_action('wp_footer', 'go_to_top'); | |
function go_to_top() { ?> | |
<script> | |
jQuery(function($) { | |
$('a.top').click(function() { | |
$('html, body').animate({scrollTop:0}, 'slow'); | |
return false; | |
}); | |
}); | |
</script> | |
<?php } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment