These days, articles on the web are getting longer and longer. Many SEO experts recommend massive content pages with thousands of words to rank on Google. It’s a different matter that more often than not, I find such articles fatiguing, but that’s a different topic! The point is that you probably have quite a bit of long-form content on your site.
The problem occurs when it’s not easy to navigate the page due to its length. Unlike a book, where you can skip immediately to the middle or even the end, webpages are linear – by default, you can’t suddenly go to the middle, the bottom, or the top. There are keyboard shortcuts of course, but a lot of people don’t use them.
One way to get around this is by having links to various parts of your page. A table of contents is a great idea to help with navigation. But when users reach the end of your article, they often want to go back right to the top. The top of the page contains the navigation links, the contact widgets, and even the site icon which takes you to the home page. As such, I recommend that you add a “Back to Top” icon to your site so that users can immediately get where they’re going.
No “Plug n Play” Solutions – Till Now!
I don’t like to install more plugins than necessary. And when trying to implement this, I wanted a “plug and play” solution purely via code. When writing this tutorial, I hardly found any solutions that fit the bill.
They usually required the following steps:
- Enqueuing the Script
- Adding CSS
- Adding images
Needless to say, this is too many moving parts for me. I’m a lazy person and like solutions that don’t need so many steps. So I took bits and pieces of code from various parts of the site and created a single block of code that will work on any site!
Adding ONE Block of Code to your Site
Open up your functions.php file, or custom plugin where you store your PHP code and paste the following:
Save your changes and you’re done! Now when you open your site, you’ll see the following at the bottom:
Clicking this arrow will take you directly to the top of the page. It’s a smooth and fast animation that should work on all browsers.
Salient Features of this Code
So far, this is the easiest way I’ve found to add the “Back to Top” icon for WordPress. You probably already have code in functions.php, so inserting this won’t be an issue. I hope you found it useful!
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!