You may notice an animation or graphic before the content loads when you visit a website. This function is known as a “preloader.” It’s widely used for branding. With pun intended, many website owners use it to hide their actual website loading speed. However, it has some real benefits as well.
This article will explore a preloader, its usefulness, and how you can easily add one to your WordPress website.
A preloader is an animation or graphic displayed while the rest of the website’s content is loading in the background. It serves as a visual cue to visitors that the website is working on loading the content, and it can help make the wait feel shorter and more engaging.
Adding a preloader to your WordPress site is relatively simple and can be done using plugins or adding custom code. Here are two easy methods:
If you prefer not to use a plugin, you can add a preloader using custom code. This method is a bit more advanced and requires editing your theme files.
1. Create the Preloader HTML and CSS:
Add the following HTML code to your header.php file just before the closing </head> tag:
<div id=”preloader”>
<div class=”loader”></div>
</div>
2. Add the following CSS code to your style.css file:
#preloader {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 9999;
background-color: #fff;
display: flex;
justify-content: center;
align-items: center;
}
.loader {
border: 16px solid #f3f3f3;
border-top: 16px solid #3498db;
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
3. Add JavaScript to Hide the Preloader:
Add the following JavaScript code to your footer.php file, just before the closing </body> tag:
<script>
window.addEventListener(‘load’, function() {
var preloader = document.getElementById(‘preloader’);
preloader.style.display = ‘none’;
});
</script>
4. Test Your Preloader:
Conclusion
A preloader is a simple yet effective tool for enhancing user experience on your WordPress website. Keeping visitors engaged and reducing perceived load time can make your site more professional and user-friendly. Whether you use a plugin or add custom code, implementing a preloader is a worthwhile addition to any site.
Live Composer is free and open-source. We invite all the users and developers to join us in plugin development.
It's super easy to create designs or extensions for Live Composer. Sell your add-ons to 30K+ plugin users.
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More