Every time you update plugins on your site, WordPress generates a flag that puts your site into maintenance mode. It does this by creating a .maintenance file.

Whilst functional (the system is protecting itself during the upgrade), this message isn’t very pretty.

From time to time, you might also see another error message – “Error establishing a database connection”. Again, functional, but wouldn’t you rather show your client a nice pretty page? It’s really easy to customise these pages, but they’re rarely included with themes as they need to sit outside of the theme folder.

Maintenance

Firstly, we need to create a file in wp-content named maintenance.php. This file is what will be displayed during maintenance mode, overriding the WordPress default functional message.

It’s worth noting, there is no point trying to use WordPress functions in this file. This is the reason that the error message exists – WordPress has gone for a nap while it upgrades.

You can do whatever you’d like in this file, even if it’s just styling up the wording/colour scheme to match your brand colours.

One thing I would recommend is adding a 503 header. This can be achieved with the following code:

Be cautious about getting this script to email you if there is an error. In all likelihood, this page is only going to be displayed for a couple of seconds at most during a site upgrade, but if you have a high traffic site, it might be that you’d receive thousands of emails.

Database connection issues

Taking care of database connection issues is also straight forward. Simply create a file called db-error.php, also in wp-content.

Of course, you’ll want to give the correct header, and this again is a 503. As database interuptions might be a little more destructive, you might want to include an email notification, however, previous caveat applies – if you have a high traffic site, you might get a LOT of emails!

Image Credit: photosteve101