DEV Community

Ngobrolin IT
Ngobrolin IT

Posted on • Edited on

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 🍻

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.