Skip to content

Instantly share code, notes, and snippets.

@IonRutz
Created March 17, 2016 12:54
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 IonRutz/285b25c0441c82080ce7 to your computer and use it in GitHub Desktop.
Save IonRutz/285b25c0441c82080ce7 to your computer and use it in GitHub Desktop.
Back to top button
First add the CSS to Dashboard > Appearances > Editor > Style.css, preferably after all the content:
#toTop {position:fixed;bottom:5px;right:5px;cursor:pointer; z-index: 99;}
Then, inside the same Dashboard > Appearances > Editor choose Footer.php in the right files and drop this code code before the </html> tag:
<img src="http://cursowebdesign.com/assets/img/to-top.png" id="toTop" alt="Back to top">
<script>
jQuery(function(){jQuery.fn.scrollToTop=function(){jQuery(this).hide().removeAttr("href");if(jQuery(window).scrollTop()!="0"){jQuery(this).fadeIn("slow")}var scrollDiv=jQuery(this);jQuery(window).scroll(function(){if(jQuery(window).scrollTop()=="0"){jQuery(scrollDiv).fadeOut("slow")}else{jQuery(scrollDiv).fadeIn("slow")}});jQuery(this).click(function(){jQuery("html, body").animate({scrollTop:0},"slow")})}});
jQuery(function(){
jQuery("#toTop").scrollToTop();
});
</script>
Keep in mind that you need to change the src="" URL with an image URL you can upload in your Dashboard Media and also that you should be doing all this changes inside a child theme, otherwise everything will get erased when you'll make the next theme update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment