Categories: WordPress Tutorials

How to Put WordPress in Maintenance Mode

You may encounter site security issues, need a change in design or replace the site content, or even perform site updates. In either of these cases, it will help you if you know how to put WordPress in maintenance mode.  

What is the Maintenance Mode?

It is a state of the website where you can inform your visitors that the site is down due to maintenance. You can display a message on the page on a live site. Furthermore, you can add the date when the website will be back again after maintenance.

WordPress will create a .maintenance file to store the maintenance message with the use of the wp_maintenance function. Once the website no longer needs the maintenance, it will delete the maintenance file to no extra files on the database.

When is the Maintenance Mode needed?

It is useful in different situations, including:

  • Testing plugins
  • Changing WordPress Theme
  • Rebranding
  • Fixing site issues

Once you activate maintenance mode in WordPress, you will work comfortably to solve the existing site issues. However, it doesn’t mean that you require a maintenance mode whenever you need a change in the site.

When you have a small site, all the minor changes can be useful in no time. But in case of a more prominent site or significant changes, the site may face downtime for a certain period. Maintenance mode is best suited in such cases.

If you have noticed, the default maintenance page in WordPress displays a single-line text on a plain white page. The user experience of your site suffers. As a site owner, you may never want to leave a wrong impression on your users. You can change the default maintenance mode page with a good design.

How to put WordPress in Maintenance Mode?

There are four different methods to enable maintenance mode in WordPress.

Built-in Maintenance Feature

Whenever you update the core, theme, or plugin, a built-in maintenance function sets up automatically. After you have started an update, you will observe a message showing that the site has entered the admin area’s maintenance mode. Usually, it does not last long. Once the update is complete, the maintenance mode is over.

This method is not under user control. The display page is created with the temporary file .maintenance whenever you run an update in WordPress.

Using Maintenance Mode Plugins

This method is suitable if an individual does not like to change code manually. All you have to do is search and install the plugin and activate the maintenance mode.

These are some of the plugins available in the WordPress plugins repository for maintenance mode.

Plugins for WordPress Maintenance Mode

Once you activate one of these plugins, you can design the maintenance mode page depending on the plugin type. You can also add content to the page and preview the page before you turn on maintenance mode.

Using a Custom Code

You can add a custom code to enter in maintenance mode manually. This method is preferable to users who do not want to use a plugin.

At first, you need to find the functions.php file of the active theme.

WordPress Maintenance Mode using Custom Code

After that, you need to add this code to the function file.

// Activate WordPress Maintenance Mode
function wp_maintenance_mode() {
if (!current_user_can('edit_themes') || !is_user_logged_in()) {
wp_die('<h1>Under Maintenance</h1><br />Website under maintenance. We will be back soon.');
}
}
add_action('get_header', 'wp_maintenance_mode');

You can change the maintenance message in this code as per your need.

Using .htaccess File

To use this method, you need to have permission to edit the .htaccess file—backup .htaccess file before you proceed in this method. Once you use this method, the request redirects to the maintenance.html file. Due to this, you will not be able to access the WordPress admin dashboard.

Rename your htaccess file something else and create a new htaccess file .htaccess and add the following code:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^356\.432\.976\.809
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ https://example.com/maintenance.html [R=307,L]

Before you write this code, first you need to create a maintenance.html file. This code replaces your homepage with a maintenance page temporarily. You can make the maintenance page online with the HTML templates.

Replace the number in the REMOTE_ADDR part with your IP address. Access to the site with that IP address is possible.

How to leave Maintenance Mode in WordPress?

As you know from the above discussion, WordPress itself creates a temporary maintenance file that deletes when the maintenance completes. If your site faces a maintenance mode problem, you need to locate the .maintenance file in your directory. Yes, it is a hidden file, so make sure to view all hidden files. You can delete the .maintenance file manually to solve the problem.

If you added a custom code to activate the maintenance move, remove that particular code from the functions.php file. If you used the .htaccess file to enter maintenance mode, keep the old .htaccess file and remove the .htaccess file used for maintenance mode.  

If you used a plugin to activate the maintenance mode, you need to turn off the plugin’s maintenance mode. Also, deactivate and delete the plugin from your site. Sometimes, the maintenance page still appears because of the cache. If you are using the cache plugin, try clearing the cache. If not, install any WordPress Cache plugins to do the same.

If you are using managed WordPress hosting, you can clear the cache from the server level with your web server’s help.

As a result, you can return the site to the normal mode if you are stuck in this process.

Precautions to be taken for Maintenance Mode

Making a backup of the site is the best precaution to roll back to an earlier working state. You can also update themes and plugins one-by-one to make sure that the site is working after the updates. In this way, you can find which theme or plugin is causing an issue if you face any.

Do not use the plugins that have a low standard of code. Before installing or updating a theme or plugin, you need to be sure that they are compatible with the version of WordPress.

Wrapping Up

You need to know how to put WordPress in maintenance mode to encounter maintenance on your site. The maintenance mode will help you to look professional to your customers. If you face any difficulty to apply this on your site, write it down in the comments below, we will be happy to help you out.

Related Posts

  1. Sticky WordPress Post
  2. How to Create Columns in WordPress
  3. How to Remove Breadcrumbs in WordPress
Amar Raj Mahato

Amar Raj Mahato is a Digital Marketer who is currently working as a content creator and SEO specialist in CodeFlist.com

Recent Posts

How to fix 504 Gateway Timeout Error?

As a visitor of the site and website owner, it is awful to experience errors on the site. Error pages… Read More

3 years ago

How to fix 403 Forbidden Error?

In the present context, every business owner maintains their own site for the online presence. When something unexpected happens with… Read More

3 years ago

How to use WebP images in WordPress?

If there are too many images on your site, they are uploaded in either PNG or JPG format. Learning how… Read More

3 years ago