DEV Community

Ngobrolin IT
Ngobrolin IT

Posted on โ€ข Edited on

2

WordPress Maintenance Mode Without Plugin

Hello, dev.. ๐Ÿ‘‹

Sometimes you need to put your website into maintenance mode and let your visitors and readers know what is going on on your website. There are many plugins to turn your WordPress site into maintenance mode. But in this tutorial, I will share with you how to enable your WordPress site into maintenance mode without a plugin. We will use the default function from WordPress core.

We will use wp_die() function from WordPress code. By default wp_die() will kills WordPress execution and displays HTML page with an error message. So we will disable the site from visitors and give messages to visitors.

Copy this code below to your themeโ€™s functions. And save it.

// Activate WordPress Maintenance Mode
add_action('get_header', function () {
    if (!current_user_can('edit_themes') || !is_user_logged_in()) {
        wp_die('<h1>Website Under Maintenance</h1><br />We have got some exciting updates lined up for you. We will be back online! Thank you. ๐Ÿ™', 'Website Under Maintenance');
    }
});
Enter fullscreen mode Exit fullscreen mode

The maintenance mode will work for your visitor. If you log in to your site, the maintenance mode will be disabled.

Good luck ๐Ÿป

Image of Timescale

Timescale โ€“ the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (1)

Collapse
 
techengagepro profile image
Ayesha Javed โ€ข

Goodjob.We can set up WordPress Maintenance mode without using a plugin by adding some code to your theme's functions.php file or by creating a custom maintenance page template.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay