Right now, you should be at the functions.php editor page, scroll to the end of the editor.
paste the following code at the end of the editor.
1. Creating link
add_action( 'wp_footer', 'back_to_top' );function back_to_top() { echo '<a id="totop" href="#">Back to Top</a>';}
2. Adding link style
add_action( 'wp_head', 'back_to_top_style' );function back_to_top_style() { echo '<style type="text/css"> #totop { position: fixed; right: 30px; bottom: 30px; display: none; outline: none; } </style>';}
3. Adding scrolling effect
add_action( 'wp_footer', 'back_to_top_script' );function back_to_top_script() { echo '<script type="text/javascript"> jQuery(document).ready(function($){ $(window).scroll(function () { if ( $(this).scrollTop() > 400 ) $("#totop").fadeIn(); else $("#totop").fadeOut(); }); $("#totop").click(function () { $("body,html").animate({ scrollTop: 0 }, 800 ); return false; }); }); </script>';}
Once you have done so, update file and your site will be updated with the function!
Join the Discussion
Write something…