Creating a Custom Maintenance Mode Page in WordPress
Basic Approach
There are three main ways to implement maintenance mode in WordPress:
- Using a plugin (easiest)
- Manual code implementation (most flexible)
- Using
.maintenance
file (quick but basic)
Method 1: Plugin Solution
For beginners or quick implementation, these plugins work well:
Method 2: Manual Code Implementation
Add this code to your theme's functions.php
file to create a custom maintenance mode:
Basic maintenance mode function that checks for admin users:
function custom_maintenance_mode() {
if (!current_user_can('edit_themes') || !is_user_logged_in()) {
wp_die(
'<h1>Website Under Maintenance</h1>
<p>We are performing scheduled maintenance. We will be back online shortly!</p>',
'Maintenance Mode',
array('response' => 503)
);
}
}
add_action('get_header', 'custom_maintenance_mode');
Advanced version with custom HTML template:
function advanced_maintenance_mode() {
if (!current_user_can('edit_themes') || !is_user_logged_in()) {
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
// Path to your maintenance template
$maintenance_template = get_template_directory() . '/maintenance.php';
if (file_exists($maintenance_template)) {
require_once($maintenance_template);
} else {
wp_die('Website under maintenance', 'Maintenance Mode', array('response' => 503));
}
die();
}
}
add_action('wp_loaded', 'advanced_maintenance_mode');
Method 3: Using .maintenance File
Create a .maintenance
file in your WordPress root directory:
<?php
$upgrading = time();
Best Practices & Security Considerations
-
Always allow admin access
- Ensure administrators can still access the site
- Test the login functionality before activating
-
Set proper HTTP headers
- Use 503 status code
- Include Retry-After header
-
Keep maintenance time short
- Plan updates in advance
- Test changes on staging first
-
Include essential information
- Expected downtime
- Contact information
- Social media links
Common Pitfalls to Avoid
- Don't forget to disable maintenance mode after updates
- Avoid caching conflicts by clearing cache after enabling/disabling
- Don't block search engine bots for extended periods
- Test maintenance mode while logged out
- Consider mobile device display
Additional Tips
Create a maintenance page template (maintenance.php
):
<!DOCTYPE html>
<html>
<head>
<title>Site Maintenance</title>
<style>
body {
text-align: center;
padding: 50px;
font-family: Arial, sans-serif;
}
.maintenance-container {
max-width: 600px;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="maintenance-container">
<h1>We'll be back soon!</h1>
<p>We're currently performing scheduled maintenance.</p>
<p>Please check back in about an hour.</p>
</div>
</body>
</html>
This template can be customized with your branding, images, and additional information as needed.