What is WordPress maintenance mode?
Marc Wagner
March 10, 2022
WordPress maintenance mode activates automatically as soon as you update your plugins, themes or WordPress core files. Your website is not available online during this time. It helps to prevent your visitors from getting ugly error messages during updates. Maintenance mode can also be activated manually to make technical adjustments and display a special maintenance mode page to your visitors.
When should you enable WordPress maintenance mode? #
Normally, you can make changes and adjustments to your WordPress website without putting it into maintenance mode. This applies to the creation of new content, minor layout adjustments and updating themes or plugins (for the latter, WordPress automatically activates maintenance mode).
However, if you want to make major changes to your website, it is worth activating the maintenance mode. This prevents the display of error messages and allows you to work undisturbed for the time being.
Note: As a rule, you should first make major changes on a staging or local development environment. After completing the work, you can then easily transfer the adjustments to the production system. WordPress is very flexible in this regard.
How do I activate the maintenance mode? #
To activate the maintenance mode manually, you just need to create a file named .maintenance in the root directory of WordPress. There you add the following content:
<?php $upgrading = time();?>
This is a lock file. This is recognized by WordPress and the maintenance mode is activated. During an update, the file is automatically created by WordPress.
The $upgrading variable is used to record when the maintenance mode was activated. This ensures that the maintenance mode is deactivated again after 10 minutes at the latest. This serves to prevent problems. By inserting the time() function, this activates an endless maintenance mode.
How do I disable WordPress maintenance mode? #
As mentioned above, WordPress automatically limits the maintenance mode to 10 minutes. However, due to technical problems, it may happen that the maintenance mode cannot be deactivated properly.
If you still want to stop the maintenance mode, you just have to delete the file .maintenance in the root directory of your WordPress installation.
Are there any alternatives to WordPress maintenance mode? #
Besides the maintenance mode of WordPress you can also access a plugin solution. Or if you are a developer yourself, the whole thing can also be solved by a custom programming.
Maintenance Plugin — Enable maintenance mode in WordPress with a plugin
The Plugin Maintenance from WebFactory Ltd. allows you to switch your WordPress website into maintenance mode with just one click. Furthermore, you can define individual texts, colors and a background image to customize the maintenance mode to your WordPress website.
The plugin is available for free in the WordPress Plugin Store. It can be installed and activated directly from your WordPress website. The options for the plugin can also be set via the WordPress backend.
How to enable WordPress maintenance mode with PHP
Ok, let’s face it. This solution is not a real maintenance mode. Instead, we use the WordPress functions and hooks to trick visitors into thinking it’s a maintenance mode.
To do this, you just need to add the following lines of code to Functions.php in your child theme folder:
function enableMaintenanceMode() {
# Enable maintenance mode only for none admins.
if ( !current_user_can( 'administrator' ) ) {
wp_die('Maintenance.');
}
}
add_action('get_header', 'enableMaintenanceMode');
The text “Maintenance” will be displayed instead of your web page. Of course, you can always replace the text with any message.
After you have finished your work, you can easily disable the maintenance mode by commenting out the add_action function:
#add_action('get_header', 'enableMaintenanceMode');
Of course, you can remove the code again, but if you work with comments, you can easily 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 maintenance mode manually, you must first connect to your website via an FTP client. Now change to the root directory of your WordPress installation.
Here you can find the file “.maintenance”. Delete the file to disable WordPress maintenance mode.
How can I enable WordPress maintenance mode manually?
Create a file named “.maintenance” in the root directory of your WordPress and add the line:
<?php $upgrading = time();?>
Which plugin can be used to enable maintenance mode on WordPress?
With the plugin Maintenance from WebFactory Ltd and the plugin WP Maintenance Mode & Comming Soon your website can be switched into maintenance mode.
Artikel von:
Marc Wagner
Hi Marc here. I’m the founder of Forge12 Interactive and have been passionate about building websites, online stores, applications and SaaS solutions for businesses for over 20 years. Before founding the company, I already worked in publicly listed companies and acquired all kinds of knowledge. Now I want to pass this knowledge on to my customers.