How to Create a WordPress Preloader with the Block Editor

How to Create a WordPress Preloader with the Block Editor

If we previously discussed how to create a preloader using Elementor, you can actually also create a WordPress preloader with the Block Editor, Gutenberg, or the default WordPress editor without using any additional plugins.

But before that, make sure you have an image to use as a preloader. It is recommended to use an animated image. For example, in this tutorial we will use this image

Cara Membuat Preloader WordPress Dengan Block Editor

Now, once you have the image, you can start with the first step

How to Create a WordPress Preloader with the Block Editor

Additionally, in this tutorial we are using the default WordPress theme Twenty Twenty-Five which already has the Theme Builder feature and allows you to edit the footer so the preloader will be applied to all pages on the website.

If you want to create a preloader on just one page, for example on the Home page, you can also edit that page using the Block Editor.

1. Open the Editor Page

Because we are going to edit the footer here, you can open the page Appearance > Editor from the WordPress dashboard

Now from the Design page, you can edit the Footer template used on your website from the menu Patterns > Footer. If you are creating a preloader for a single page, you can skip this step

3. Add a Stack Element

Now from the WordPress block editor page, add an element named Stack

4. Customize the Stack

Before adding more elements, you can customize the Stack with options like those in the following image

In addition to those customizations, make sure you add a class from the menu Advanced > Additional CSS class(es) with any name, for example wpgan-preload (if you change the class, you must change the preload script used)

5. Add a Spacer

The Spacer here is used to center the image on the screen. Because it is different from Elementor where you can customize the layout directly, with the Block Editor you need to use a trick

6. Customize the Spacer

So that the image can be centered on the screen later, you can customize the spacer by setting the Specify a fixed height section to a value between 30-50%

7. Add an Image

Now you can add an image right below the Spacer you added and make sure the image is inside the stack

8. Customize the Image

By default, the image size might be too large or too small, so here you need to customize the image size, for example with a width of 150px.

9. Add Custom HTML

Finally, you just need to add custom HTML below the image block and you can fill it with the following code

<script>    document.addEventListener('DOMContentLoaded', function () {        const preloadElement = document.querySelector('.wpgan-preload');
        setTimeout(function () {            if (preloadElement) {                preloadElement.style.display = 'none';             }        }, 2000);    });</script><style>.wpgan-preload {    position: fixed;    display: flex;    align-items: center;    top: 0;    left: 0;    min-height: 100vh;    width: 100%;    height: 100%;    background: #fff;     z-index: 99;}</style>

After adding that code, the preloader will not run immediately inside the editor, so you need to check the preview

10. Save Changes and View Results

Now you can save the changes you have made, then try opening a page on your website. If successful, it will look like this when accessed

That is an easy way to Create a WordPress Preloader with the Block Editor that you can try if your website uses the Block Editor.

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...