How to Put WordPress Site Into Maintenance Mode

Sometimes, you may have the need to put your website into maintenance mode for upgrades. This would make your website temporarily unavailable to public access. You wouldn’t want errors to pop up when you are running important updates in the background, right?

There are several ways of putting a website into maintenance mode, and the technical details may differ accordingly. If you are on WordPress, here are 3 ways to put your website into maintenance mode.

Using .Htaccess

If you are using the Apache server, you can use.htaccess to control access of the directories within the server and send a response code of the server status.

To put the website into maintenance mode, you can use the 503 status code, which indicates that the server is temporarily unavailable.

Before we specify anything in .htaccess, however, we need to create a new file in.html or .php format, and add a message in the file, e.g.

Sorry we are down for maintenance, but we’ll be back up shortly.

Style your page. Next, open the .htaccess file in your server, and add the following:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=503,L]
</IfModule>

This will set the server status code to 503, while also redirects visitors to the maintenance page. You can set your IP address with the following line RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000 so that you will still be able to access your website.

WordPress Built-in Maintenance Page

When updating WordPress, plugins, or themes, you can create a file called .maintenance that says

Briefly unavailable for scheduled maintenance. Check back in a minute.

This file will be automatically removed when the process is completed – if the process fails, the file could get stuck in your server, so you have to remove it manually.

The problem is that .maintenance is not customizable, as it is generated dynamically.

So, if your emphasis is on the overall appearance of your website, you can create a file named maintenance.php, which you can customize with CSS, then put inside thewp-content folder. That way, the next time you update WordPress or plugins, WordPress will use the content inside this file.

The function is specified in wp-includes/load.php, like so.

if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
	require_once( WP_CONTENT_DIR . '/maintenance.php' );
	die();
}

Using a Plugin

There are several WordPress plugins available to help put your website into maintenance mode, but my personal favorite is the Maintenance Mode plugin by Michael Wohrer. Although this plugin hasn’t been updated for about 2 years now, it still works perfectly.

Using the Maintenance Mode plugin, you can simply activate or deactivate the maintenance mode with a few clicks. You can also specify how long the website will be in maintenance mode.

In addition, this plugin comes with a default theme template to be displayed when the maintenance mode is activated. You can also use your own theme by creating a 503.php file and uploading it to your theme directory. Just go to the Maintenance Mode Setting page and select the 503.php file you have created.

Conclusion

We hope you found this tutorial useful in helping you run your WordPress site more efficiently. For further reading on the subject, you can head over to the following sites.

WebsiteFacebookTwitterInstagramPinterestLinkedInGoogle+YoutubeRedditDribbbleBehanceGithubCodePenWhatsappEmail