What is WordPress maintenance mode?

Marc Wag­ner

March 10, 2022

4 min read|

Word­Press main­ten­an­ce mode acti­va­tes auto­ma­ti­cal­ly as soon as you update your plug­ins, the­mes or Word­Press core files. Your web­site is not available online during this time. It helps to pre­vent your visi­tors from get­ting ugly error mes­sa­ges during updates. Main­ten­an­ce mode can also be acti­va­ted manu­al­ly to make tech­ni­cal adjus­t­ments and dis­play a spe­cial main­ten­an­ce mode page to your visi­tors.

When should you enable WordPress maintenance mode? #

Nor­mal­ly, you can make chan­ges and adjus­t­ments to your Word­Press web­site wit­hout put­ting it into main­ten­an­ce mode. This appli­es to the crea­ti­on of new con­tent, minor lay­out adjus­t­ments and updating the­mes or plug­ins (for the lat­ter, Word­Press auto­ma­ti­cal­ly acti­va­tes main­ten­an­ce mode).

Howe­ver, if you want to make major chan­ges to your web­site, it is worth acti­vat­ing the main­ten­an­ce mode. This pre­vents the dis­play of error mes­sa­ges and allows you to work undis­tur­bed for the time being.

Note: As a rule, you should first make major chan­ges on a sta­ging or local deve­lo­p­ment envi­ron­ment. After com­ple­ting the work, you can then easi­ly trans­fer the adjus­t­ments to the pro­duc­tion sys­tem. Word­Press is very fle­xi­ble in this regard.

How do I activate the maintenance mode? #

To acti­va­te the main­ten­an­ce mode manu­al­ly, you just need to crea­te a file named .main­ten­an­ce in the root direc­to­ry of Word­Press. The­re you add the fol­lo­wing con­tent:

<?php $upgrading = time();?>

This is a lock file. This is reco­gni­zed by Word­Press and the main­ten­an­ce mode is acti­va­ted. During an update, the file is auto­ma­ti­cal­ly crea­ted by Word­Press.

The $upgrading varia­ble is used to record when the main­ten­an­ce mode was acti­va­ted. This ensu­res that the main­ten­an­ce mode is deac­ti­va­ted again after 10 minu­tes at the latest. This ser­ves to pre­vent pro­blems. By inser­ting the time() func­tion, this acti­va­tes an end­less main­ten­an­ce mode.

How do I disable WordPress maintenance mode? #

As men­tio­ned abo­ve, Word­Press auto­ma­ti­cal­ly limits the main­ten­an­ce mode to 10 minu­tes. Howe­ver, due to tech­ni­cal pro­blems, it may hap­pen that the main­ten­an­ce mode can­not be deac­ti­va­ted pro­per­ly.

If you still want to stop the main­ten­an­ce mode, you just have to dele­te the file .main­ten­an­ce in the root direc­to­ry of your Word­Press instal­la­ti­on.

Are there any alternatives to WordPress maintenance mode? #

Bes­i­des the main­ten­an­ce mode of Word­Press you can also access a plug­in solu­ti­on. Or if you are a deve­lo­per yours­elf, the who­le thing can also be sol­ved by a cus­tom pro­gramming.

Maintenance Plugin — Enable maintenance mode in WordPress with a plugin

WordPress Wartungsmodus durch ein Plugin aktivieren.
Main­ten­an­ce Plug­in for Word­Press

The Plug­in Main­ten­an­ce from Web­Fac­to­ry Ltd. allows you to switch your Word­Press web­site into main­ten­an­ce mode with just one click. Fur­ther­mo­re, you can defi­ne indi­vi­du­al texts, colors and a back­ground image to cus­to­mi­ze the main­ten­an­ce mode to your Word­Press web­site.

The plug­in is available for free in the Word­Press Plug­in Store. It can be instal­led and acti­va­ted direct­ly from your Word­Press web­site. The opti­ons for the plug­in can also be set via the Word­Press backend.

How to enable WordPress maintenance mode with PHP

Ok, let’s face it. This solu­ti­on is not a real main­ten­an­ce mode. Ins­tead, we use the Word­Press func­tions and hooks to trick visi­tors into thin­king it’s a main­ten­an­ce mode.

To do this, you just need to add the fol­lo­wing lines of code to Functions.php in your child the­me fol­der:

function enableMaintenanceMode() {
     # Enable maintenance mode only for none admins.
     if ( !current_user_can( 'administrator' ) ) {
        wp_die('Maintenance.'); 
     }
}

add_action('get_header', 'enableMaintenanceMode');

The text “Main­ten­an­ce” will be dis­play­ed ins­tead of your web page. Of cour­se, you can always replace the text with any mes­sa­ge.

After you have finis­hed your work, you can easi­ly disable the main­ten­an­ce mode by com­men­ting out the add_action func­tion:

#add_action('get_header', 'enableMaintenanceMode');

Of cour­se, you can remo­ve the code again, but if you work with comm­ents, you can easi­ly access it again at any time.

Frequently asked questions about WordPress maintenance mode #

WordPress hangs in maintenance mode, what can I do?

To exit the main­ten­an­ce mode manu­al­ly, you must first con­nect to your web­site via an FTP cli­ent. Now chan­ge to the root direc­to­ry of your Word­Press instal­la­ti­on.

Here you can find the file “.main­ten­an­ce”. Dele­te the file to disable Word­Press main­ten­an­ce mode.

How can I enable WordPress maintenance mode manually?

Crea­te a file named “.main­ten­an­ce” in the root direc­to­ry of your Word­Press and add the line:
<?php $upgrading = time();?>

Which plugin can be used to enable maintenance mode on WordPress?

With the plug­in Main­ten­an­ce from Web­Fac­to­ry Ltd and the plug­in WP Main­ten­an­ce Mode & Com­ming Soon your web­site can be swit­ched into main­ten­an­ce mode.

88e86fcb816eff22bc917094df2862d8dd5c0e978b333e6dd5f36f808990c261 96

Arti­kel von:

Marc Wag­ner

Hi Marc here. I’m the foun­der of Forge12 Inter­ac­ti­ve and have been pas­sio­na­te about buil­ding web­sites, online stores, appli­ca­ti­ons and SaaS solu­ti­ons for busi­nesses for over 20 years. Befo­re foun­ding the com­pa­ny, I alre­a­dy work­ed in publicly lis­ted com­pa­nies and acqui­red all kinds of know­ledge. Now I want to pass this know­ledge on to my cus­to­mers.

Hast du eine Fra­ge? Hin­ter­lass bit­te einen Kom­men­tar