DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Dhimas Kirana
Dhimas Kirana

Posted on

How to Enable WordPress Maintenance Mode Without a Plugin

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.

Top comments (0)

DEV

Thank you.

Β 
Thanks for visiting DEV, we’ve worked really hard to cultivate this great community and would love to have you join us. If you’d like to create an account, you can sign up here.