<\/span><\/h2>\n\nNow we can add some code to the functions.php file to create the \u201cGo to Top\u201d button. Insert the following snippet of code:\n<\/p>\n
function add_my_script() {\nwp_enqueue_script('back-to-top', get_template_directory_uri() . '\/js\/back-to-top.js', array('jquery'), '1.0', true);\n}\nadd_action( 'wp_enqueue_scripts', 'add_my_script' );\n<\/code><\/pre>\n\nThis code tells WordPress to add the \u201cback-to-top.js\u201d file to your website.\n<\/p>\n
<\/span>Step 3: Create the \u201cback-to-top.js\u201d File<\/span><\/h2>\n\nNext, you will need to make a file called \u201cback-to-top.js\u201d and paste this code into it:\n<\/p>\n
jQuery(document).ready(function() {\n jQuery(window).scroll(function() {\n if (jQuery(this).scrollTop() > 100) {\n jQuery('#back-to-top').fadeIn();\n } else {\n jQuery('#back-to-top').fadeOut();\n }\n });\n\n jQuery('#back-to-top').click(function() {\n jQuery('body,html').animate({\n scrollTop: 0\n }, 600);\n return false;\n});\n});\n<\/code><\/pre>\n\nThis code uses jQuery to create a function that will control your \u201cGo to Top\u201d button. When a user scrolls down the page, the button will appear. When it is clicked, the user is taken back to the top of the page.\n<\/p>\n
<\/span>Step 4: Save and Upload<\/span><\/h2>\n\nSave the \u201cback-to-top.js\u201d file and upload it to your WordPress website using an FTP client. Place it in this directory:\n<\/p>\n
wp-content\/themes\/your-theme-name\/js\/\n<\/code><\/pre>\n\nNote: Replace \u201cyour-theme-name\u201d with your theme\u2019s name.\n<\/p>\n
<\/span>Step 5: Add the Button HTML and CSS<\/span><\/h2>\n\nWe can now add the \u201cGo to Top\u201d button to your site by editing the theme\u2019s footer.php file. Look for the closing <\/body> tag in your footer.php and add this code above it:\n<\/p>\n
<a href=\"#\" id=\"back-to-top\" title=\"Back to top\">↑<\/a>\n<\/code><\/pre>\n\nThis code creates the HTML and CSS for the button that will display on your website.\n<\/p>\n
<\/span>Step 6: Enjoy!<\/span><\/h2>\n\nAfter saving the changes to your footer.php file, refresh your website and see the \u201cGo to Top\u201d button in action. Adding this button is an easy process that can vastly improve user experience on your WordPress website. Your users can now effortlessly navigate through your site\u2019s content with the simple click of a button. Happy scrolling!<\/p>\n","protected":false},"excerpt":{"rendered":"
Introducing the \u201cGo to Top\u201d Button for WordPress Are you tired of endlessly scrolling to the top of a web page on your WordPress website?…<\/p>\n","protected":false},"author":1,"featured_media":7209,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3287],"tags":[],"jetpack_featured_media_url":"https:\/\/mauricemuteti.info\/wp-content\/uploads\/2023\/03\/WORDPRESS-ULTIMATE-GUIDE-How-To-step-by-step-Tutorial.png","_links":{"self":[{"href":"https:\/\/mauricemuteti.info\/wp-json\/wp\/v2\/posts\/10075"}],"collection":[{"href":"https:\/\/mauricemuteti.info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mauricemuteti.info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mauricemuteti.info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mauricemuteti.info\/wp-json\/wp\/v2\/comments?post=10075"}],"version-history":[{"count":0,"href":"https:\/\/mauricemuteti.info\/wp-json\/wp\/v2\/posts\/10075\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mauricemuteti.info\/wp-json\/wp\/v2\/media\/7209"}],"wp:attachment":[{"href":"https:\/\/mauricemuteti.info\/wp-json\/wp\/v2\/media?parent=10075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mauricemuteti.info\/wp-json\/wp\/v2\/categories?post=10075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mauricemuteti.info\/wp-json\/wp\/v2\/tags?post=10075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}