Skip to content

Instantly share code, notes, and snippets.

@vfontjr
Created May 3, 2020 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vfontjr/c0d69fbb712f603ba1ed83732da50ffb to your computer and use it in GitHub Desktop.
Save vfontjr/c0d69fbb712f603ba1ed83732da50ffb to your computer and use it in GitHub Desktop.
<?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