Why Use Maintenance Mode?
A maintenance mode page helps you keep visitors informed while you're updating your site, fixing issues, or making significant changes. It's essential for providing a professional experience during site maintenance.
Method 1: Using WordPress Core Function
The simplest way to enable maintenance mode is using WordPress's built-in functionality. Create a file named maintenance.php
in your site's root directory:
Create a basic maintenance page:
<?php
$protocol = $_SERVER["SERVER_PROTOCOL"];
if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) {
$protocol = 'HTTP/1.0';
}
header( "$protocol 503 Service Unavailable", true, 503 );
header( 'Content-Type: text/html; charset=utf-8' );
header( 'Retry-After: 600' );
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Site Maintenance</title>
<style>
body { font-family: Arial, sans-serif; padding: 50px; text-align: center; }
h1 { font-size: 36px; margin-bottom: 20px; }
p { font-size: 18px; }
</style>
</head>
<body>
<h1>We'll be back soon!</h1>
<p>We're currently updating our site. Please check back later.</p>
</body>
</html>
Method 2: Using Custom Code in functions.php
Add this code to enable maintenance mode for non-admin users:
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. Please check back soon.</p>', 'Maintenance Mode', array('response' => 503));
}
}
add_action('get_header', 'custom_maintenance_mode');
Method 3: Using .htaccess (Apache Servers)
Add these rules to your .htaccess file:
# BEGIN Maintenance
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$
RewriteRule ^(.*)$ /maintenance.html [R=307,L]
</IfModule>
# END Maintenance
Best Practices
- Always set proper HTTP status codes (503)
- Include a Retry-After header
- Allow admin access during maintenance
- Keep maintenance periods short
- Provide clear information about downtime
- Include your logo and branding
- Add an estimated completion time if possible
Security Considerations
- Don't expose sensitive information on the maintenance page
- Ensure admin access remains secure
- Monitor maintenance mode status
- Remove maintenance files after completion
- Keep IP whitelist updated if using one
Recommended Plugins
-
WP Maintenance Mode
- Feature-rich, customizable templates
- Countdown timer option
-
Plugin Page
-
SeedProd
- Coming soon and maintenance mode pages
- Custom designs and templates
-
Plugin Website
Common Pitfalls
- Forgetting to disable maintenance mode
- Not testing maintenance page appearance
- Blocking search engines unnecessarily
- Using incorrect HTTP status codes
- Not providing access to administrators
- Forgetting to backup before maintenance
Quick Implementation Tips
- Test maintenance mode with private browsing
- Keep a backup of your IP for whitelist access
- Set up monitoring to ensure maintenance mode doesn't stay active accidentally
- Consider using a staging site for major updates instead
- Include contact information on the maintenance page
This solution provides various methods to implement maintenance mode, allowing you to choose the one that best fits your needs while maintaining SEO-friendly practices and user experience.