How to Enable Maintenance Mode in WordPress: A Step-by-Step Guide with Code Snippets

If you’re planning to update your WordPress site or perform any major changes, enabling maintenance mode is a smart way to minimize any disruptions to your visitors. By enabling maintenance mode, you can display a customized message or page that informs visitors that your site is temporarily offline while you make updates or perform maintenance tasks.

In this tutorial, we’ll show you how to enable maintenance mode in WordPress using two different methods: creating a maintenance page or using the wp_die() function. First, we’ll walk you through the process of creating a custom maintenance page that visitors will see when maintenance mode is enabled. Then, we’ll provide a code snippet that you can add to your site’s functions.php file to automatically redirect visitors to the maintenance page using the wp_die() function.

Whether you’re a WordPress beginner or an experienced user, this guide will help you enable maintenance mode quickly and easily. Let’s get started!

Option 1: Create a Custom Maintenance Page

Step 1: Create a Maintenance Page

To create a custom maintenance page in WordPress, follow these steps:

  1. Log in to your WordPress dashboard and click on “Pages”.
  2. Click on “Add New” to create a new page.
  3. Give your page a title, such as “Maintenance Mode” or “Site Under Maintenance”.
  4. Add your custom message to the page, explaining why your site is in maintenance mode and when it will be back online.
  5. Add images or other media to the page using the WordPress editor.
  6. Publish the page or save it as a draft.

Step 2: Add the Maintenance Mode Function to Your Functions.php File

To add the maintenance mode function to your WordPress theme’s functions.php file, use the following code snippet:

function wp_maintenance_mode() {
	if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
		$maintenance_page_url = ''; // Replace with the URL of your maintenance page
		wp_safe_redirect( $maintenance_page_url );
add_action('get_header', 'wp_maintenance_mode');

Option 2: Use the wp_die() Function

Step 1: Add the Maintenance Mode Function to Your Functions.php

File To use the wp_die() function to put your site in maintenance mode, add the following code snippet to your WordPress theme’s functions.php file:

function wp_maintenance_mode() {
	if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
		$message = 'This site is currently in maintenance mode. Please try again later.';
		wp_die( $message, 'Maintenance Mode', array( 'response' => 503 ) );
add_action('get_header', 'wp_maintenance_mode');

Putting your WordPress site in maintenance mode is crucial for ensuring that your site remains functional and accessible to visitors. Using a custom maintenance page or the wp_die() function are both simple and easy ways to put your site in maintenance mode. By following the steps outlined in this tutorial, you can put your WordPress site in maintenance mode in just a few simple steps.

Support 🐶

If you found this article helpful, got a question or spotted an error/typo... Do well to leave your feedback in the comment section or help spread it by sharing this article. If you're feeling generous (and I hope you do) you can definitely help me by getting me a cup of coffee ☕.

You may like these too!

Leave a Reply

Your email address will not be published. Required fields are marked *