How to Set Up a Maintenance Mode in WordPress

Marco T Jan 7, 2025 Maintenance
How can I show a message to visitors that my website is being fixed?
What is the methodology for implementing a maintenance mode in WordPress to inform users about scheduled maintenance effectively?
Andy answered Jan 7, 2025

Understanding Maintenance Mode

Maintenance mode is essential when you're updating your WordPress site, fixing issues, or making significant changes. Here's how to implement it effectively.

Manual Implementation

Method 1: Using wp-config.php

Add this code to wp-config.php to enable WordPress's built-in maintenance mode:

define('WP_MAINTENANCE', true);

Method 2: Custom Maintenance Page

Create a maintenance.php file in your WordPress root directory:

<?php
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
?>
<!DOCTYPE html>
<html>
<head>
    <title>Site Maintenance</title>
    <style>
        body { text-align: center; padding: 150px; }
        h1 { font-size: 40px; }
        body { font: 20px Helvetica, sans-serif; color: #333; }
        article { display: block; max-width: 650px; margin: 0 auto; }
    </style>
</head>
<body>
    <article>
        <h1>We'll be back soon!</h1>
        <div>
            <p>Sorry for the inconvenience. We're performing some maintenance at the moment.</p>
            <p>— The Team</p>
        </div>
    </article>
</body>
</html>

Plugin Solutions

  1. WP Maintenance Mode

  2. SeedProd

Best Practices

  1. Allow Admin Access

    • Ensure administrators can still access the site
    • Test maintenance mode while logged out
  2. SEO Considerations

    • Use 503 status code (temporary unavailable)
    • Set appropriate retry-after header
  3. User Experience

    • Display estimated downtime
    • Provide contact information
    • Keep design simple and professional

Security Tips

  1. Protect maintenance.php file
  2. Use WordPress authentication checks
  3. Remove maintenance mode files after use

Add this code to maintenance.php to allow admin access:

<?php
if (current_user_can('administrator')) {
    return false;
}

Common Pitfalls to Avoid

  1. Don't forget to disable maintenance mode
  2. Avoid caching conflicts
  3. Test on multiple browsers
  4. Consider mobile responsiveness

Advanced Implementation

Custom function for maintenance mode with admin access:

function custom_maintenance_mode() {
    if (!current_user_can('administrator')) {
        wp_die(
            '<h1>Under Maintenance</h1>
            <p>Our website is currently undergoing scheduled maintenance.</p>
            <p>Please try again later.</p>',
            'Maintenance Mode',
            array(
                'response' => 503,
                'back_link' => true
            )
        );
    }
}
add_action('get_header', 'custom_maintenance_mode');

Hooks Integration

Add this code to functions.php for a simple maintenance notice:

function maintenance_notice() {
    if (!is_user_logged_in()) {
        echo '<div style="background: #f56e28; color: #fff; text-align: center; padding: 10px;">
            Site is under maintenance. Some features might be limited.
        </div>';
    }
}
add_action('wp_body_open', 'maintenance_notice');

Remember to always test maintenance mode implementation in a staging environment first and ensure it works correctly before applying it to your live site.