WordPress manual maintenance mode.

Updating your website can take some time, and while you do it, a maintenance notice is always better than a non-functioning website. It’s especially important to use a proper maintenance notice page. On big websites which are regularly crawled by search engines, it is very important not to 404 your pages for search robots.

In WordPress, the default maintenance message is invoked automatically when upgrading your site. While it gives the proper response headers (503 – Service Unavailable), it is quite an ugly message. I recently created a (switchable) WordPress custom maintenance mode (and custom maintenance page) for a WordPress website I have been developing. All without the tedious process of uploading a .maintenance file, or installing a plug-in. It is quite simple to do, I’ll explain below:

WordPress custom maintenance page

You can make your own custom maintenance page by creating a maintenance.php file, and put it directly inside (in the root of) the wp-content folder. You can do whatever you want in this file; just make sure it can function on its own and doesn’t rely on your theme (depending on the nature of your maintenance work, your theme might not be available). There is just one important bit to add: proper response headers. You can do this by adding the following PHP-code at the top of the file:

This will activate maintenance mode if the MAINTENANCE constant is set to true (first line), but it will not activate maintenance for the admin area, nor for users that have admin-privileges. This differs from WordPress’ own maintenance mode (not even the admin panel will be available during WordPress maintenance mode), and allows you to test things while your regular visitors will be presented with the maintenance page you created earlier.

Notice

Important notice: as you specify the maintenance mode in your current theme’s functions.php, be aware that if you switch themes during maintenance, you make sure that the theme you switch to also has these lines, and has maintenance mode activated! Otherwise, maintenance mode will be deactivated on switching themes, potentially showing your visitors an untested theme.

Thanks for this post. But when maintenance mode is set to “true”, I’m not able to access the wp-admin area. I used your code and a simple line of HTML. My message appears, but the function doesn’t appear to work as you describe.