Activating WordPress Maintenance Mode with WP-CLI


In the world of managing websites, WordPress is a major player, running a large part of the internet. One important but often ignored feature in WordPress is Maintenance Mode. This feature might seem basic, but it’s actually very useful and important.

So, what is Maintenance Mode, and why is it so important for anyone running a WordPress site? Also, how does using WP-CLI, a powerful tool for command-line management, change how we use this mode? As we explore WordPress maintenance, we’ll look at not just how to use Maintenance Mode, but also why it’s beneficial.

Understanding Maintenance Mode in WordPress

Maintenance mode is a built-in feature in WordPress that allows you to temporarily make your website inaccessible to visitors while you perform updates, fixes, or other changes.

When maintenance mode is active, your site displays a default message or a custom page to inform visitors that the site is under maintenance and will be back online shortly.

This feature is crucial to ensure a smooth user experience and prevent users from encountering errors or issues while you’re working on the site. There are several situations in which activating maintenance mode can be beneficial, such as:

  • Updating WordPress core, themes, or plugins
  • Implementing significant design or layout changes
  • Fixing bugs or addressing security vulnerabilities
  • Performing site migration or server upgrades
  • Testing new features or configurations in a live environment

Benefits of Using Maintenance Mode

Using maintenance mode comes with a variety of advantages:

  • Maintenance mode prevents visitors from encountering errors, broken pages, or incomplete content while you’re working on the site.
  • Temporarily taking your site offline can help reduce the load on your server during resource-intensive tasks, such as updates or migrations.
  • Activating maintenance mode limits the site’s exposure to potential threats while you address security vulnerabilities or perform other sensitive tasks.
  • Displaying a custom maintenance page conveys a sense of professionalism, showing that you care about your users’ experience and the quality of your website.
  • Maintenance mode allows you to work on your site without worrying about the impact of your changes on live visitors, helping you focus on the task at hand.

What is WP-CLI?

WP-CLI, short for WordPress Command Line Interface, is a powerful command-line tool that enables you to manage and maintain your WordPress website without using a web browser.

WP-CLI allows you to perform various tasks, such as installing and updating plugins, managing themes, configuring settings, and much more, all through the convenience of your command line or terminal.

Installing and Updating WP-CLI

Before you can use WP-CLI, you need to install it on your local machine or server. To install WP-CLI, follow these steps:

  1. Download the latest release of WP-CLI from the official website (
  2. Make the downloaded file executable and move it to a location in your system’s PATH.
  3. Verify the installation by running the wp --info command in your terminal.

To update WP-CLI, you can use the wp cli update command. This ensures you always have the most recent version of the tool, including the latest features and security updates.

Activating Maintenance Mode Using WP-CLI

Open your command line or terminal and navigate to your WordPress installation directory. Run the following command to activate maintenance mode:

wp maintenance-mode activate

This command will create a .maintenance file in the root of your WordPress installation, which signals to the system that the site is in maintenance mode. By default, WordPress will display a generic “Briefly unavailable for scheduled maintenance. Check back in a minute.” message to visitors.

To display a custom message while your site is in maintenance mode, you can create a simple PHP script with the desired content. Create a new file named maintenance.php in your wp-content directory and add the following code:

header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
<!DOCTYPE html>
    <title>Maintenance Mode</title>
    <h1>Our website is currently under maintenance.</h1>
    <p>We apologize for the inconvenience. Please check back soon.</p>

Feel free to customize the HTML content to fit your needs. The Retry-After header in this example informs search engines that the site will be back online in an hour (3600 seconds).

Verifying Maintenance Mode Activation

To confirm that maintenance mode is active, you can visit your website in a web browser or run the following WP-CLI command:

wp maintenance-mode status

If maintenance mode is active, the command will return “Activated.”

Deactivating Maintenance Mode with WP-CLI

After completing your maintenance tasks, it’s time to deactivate maintenance mode and make your site accessible to visitors again.

Open your command line or terminal and navigate to your WordPress installation directory. Run the following command to deactivate maintenance mode:

wp maintenance-mode deactivate

This command will remove the .maintenance file from the root of your WordPress installation, signaling that the site is no longer in maintenance mode.


In conclusion, WP-CLI provides a powerful and efficient way to manage WordPress maintenance mode.

By following the steps outlined in this blog post, you can easily activate and deactivate maintenance mode, ensuring minimal disruption for your users while you work on updates, fixes, or other changes.

As you become more familiar with WP-CLI, you’ll discover even more possibilities for streamlining your WordPress management tasks. Keep exploring and experimenting with WP-CLI to make the most of this powerful tool and maintain your website with ease and professionalism.