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 ๐Ÿป

Billboard image

Monitor more than uptime.

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

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.

Sentry image

See why 4M developers consider Sentry, โ€œnot bad.โ€

Fixing code doesnโ€™t have to be the worst part of your day. Learn how Sentry can help.

Learn more

๐Ÿ‘‹ Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay