Maintenance mode in WordPress
Maintenance mode is the “be right back” state of your website. You should use it any time you are changing the WordPress code or making anything else with a non-zero possibility to fail and affect a user experience.
You’ve probably noticed that WordPress is actually turning the built-in maintenance mode while upgrading the WP core, or adding new plugins.
In this article, you’ll learn how it works, how to turn the maintenance mode on manually, and how to make it look better.
How the built-in maintenance mode works
When you click the “upgrade WordPress” button, Wordpress is inserting the .maintenance php file into the site’s root directory with $upgrading variable set to time().
Every single time someone enters your site, WordPress is looking for this particular file and if it exists, WordPress is comparing the $upgrading variable with the time() value. If the difference is less than 600 seconds (10 minutes), the maintenance mode function is looking for a custom maintenance.php inside wp-content directory.
If it exists, WordPress loads that file and exits the compilation process.
If not, the maintenance function compiles the built-in maintenance landing page and ends with the compilation process. What’s important, WordPress handles the maintenance mode well with a proper http code sending to a user.
Find out why the proper http code is important.
How to make a custom maintenance mode landing page?
To make a custom maintenance mode landing page, you just need to make your own php script and save it into wp-content directory as maintenance.php file. Every time your site is in the maintenance mode, WordPress will look for this file and compile it, ignoring the built-in landing page.
To make it easier for you, we’ve made an example script. You can grab it from our GitHub repository and customise it any way you like.
How to turn on the maintenance mode manually?
If you would like to turn on the maintenance mode manually, without any plugin you just need to insert the .maintenance file into your WordPress main folder.
We made the file for you, extending it with an IP white list and secret key white list support. You can grab it from our GitHub repo as well as the maintenance.php example file.