How to Set Up a Maintenance Mode Page in WordPress

Marek S Jan 4, 2025 WordPress Maintenance
How do I show a 'be right back' message when I’m working on my website?
What are the methods to implement a maintenance mode page in WordPress without affecting SEO?
Andy answered Jan 4, 2025

Understanding Maintenance Mode in WordPress

Maintenance mode is crucial when you're updating your site, making major changes, or troubleshooting issues. Here are multiple approaches to implement it effectively.

Method 1: Using WordPress Core Function

The simplest built-in approach uses .maintenance file:

Create a temporary maintenance file in your site root:

$maintenance = '<?php $upgrading = time(); ?>';
file_put_contents( ABSPATH . '.maintenance', $maintenance );

Remove maintenance mode when done:

unlink( ABSPATH . '.maintenance' );

Method 2: Custom Function Approach

Add this code to your theme's functions.php or custom plugin:

function custom_maintenance_mode() {
    if (!current_user_can('edit_themes') && !is_admin()) {
        wp_die('
            <h1>Site Under Maintenance</h1>
            <p>We are performing scheduled maintenance. We will be back online shortly!</p>
            <style>
                body{text-align:center;padding:50px;}
                h1{font-size:28px;color:#444;}
                p{font-size:16px;}
            </style>
        ', 'Maintenance Mode', ['response' => 503]);
    }
}
add_action('get_header', 'custom_maintenance_mode');

Method 3: Using wp-config.php

Add this to wp-config.php for temporary maintenance mode:

define('WP_MAINTENANCE_MODE', true);

Best Practices & SEO Considerations

  1. Always return 503 HTTP status code (Service Unavailable)
  2. Set a Retry-After header
  3. Allow admin access during maintenance
  4. Keep maintenance periods short
  5. Use a countdown timer if possible

Security Tips

  1. Always check user capabilities
  2. Protect maintenance page from unauthorized access
  3. Remove maintenance files after completion
  4. Monitor access logs during maintenance

Recommended Plugins

  1. WP Maintenance Mode
  1. SeedProd
  1. Maintenance

Common Pitfalls to Avoid

  1. Forgetting to disable maintenance mode
  2. Not testing maintenance page appearance
  3. Blocking search engine bots permanently
  4. Not providing admin access
  5. Using incorrect HTTP status codes

Advanced Implementation

Custom maintenance mode with timer and admin bypass:

function advanced_maintenance_mode() {
    if (!current_user_can('edit_themes') && !is_admin()) {
        header('HTTP/1.1 503 Service Temporarily Unavailable');
        header('Retry-After: 3600');
        header('Content-Type: text/html; charset=utf-8');
        ?>
        <!DOCTYPE html>
        <html>
        <head>
            <title>Maintenance Mode</title>
            <style>
                body { font-family: Arial, sans-serif; text-align: center; padding: 50px; }
                .container { max-width: 600px; margin: 0 auto; }
                .countdown { font-size: 24px; margin: 20px 0; }
            </style>
        </head>
        <body>
            <div class="container">
                <h1>We'll Be Right Back</h1>
                <p>Our site is currently undergoing scheduled maintenance.</p>
                <div class="countdown" id="countdown"></div>
            </div>
            <script>
                // Set maintenance end time (1 hour from now)
                var endTime = new Date().getTime() + (1 * 60 * 60 * 1000);
                var countdown = setInterval(function() {
                    var now = new Date().getTime();
                    var distance = endTime - now;
                    var hours = Math.floor(distance / (1000 * 60 * 60));
                    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                    var seconds = Math.floor((distance % (1000 * 60)) / 1000);
                    document.getElementById("countdown").innerHTML = hours + "h " + minutes + "m " + seconds + "s ";
                    if (distance < 0) {
                        clearInterval(countdown);
                        document.getElementById("countdown").innerHTML = "COMPLETED";
                    }
                }, 1000);
            </script>
        </body>
        </html>
        <?php
        die();
    }
}
add_action('template_redirect', 'advanced_maintenance_mode');

This solution provides all essential features while maintaining SEO friendliness and user experience.