
This WordPress snippet enables maintenance mode, displaying a customizable message to all site visitors except administrators. Easily integrate this code to temporarily take your WordPress site offline for updates or maintenance, ensuring a smooth user experience.
<?php
add_action('template_redirect', function() {
if( !current_user_can( 'manage_options') && !is_admin()) {
status_header(503);
?>
<h1 style="font-family:system-ui;text-align:center;margin-top:100px;">
The site is currently in maintenance mode. Check back soon!
</h1>
<?php
exit;
}
});
Follow these simple steps to enable maintenance mode for non-admin users:
That’s it! Your site is now in maintenance mode for all non-administrator users.
Maintenance mode is a feature that temporarily displays a custom page to visitors while you work on your site. Instead of showing broken pages, error messages, or incomplete updates, visitors see a professional message explaining that your site is undergoing maintenance.
The code snippet provided sends a proper HTTP 503 status code, which tells search engines that your site is temporarily unavailable and they should check back later. This is important for SEO because it prevents search engines from thinking your site has permanently disappeared or encountered serious errors.
You should enable maintenance mode during several scenarios. Major plugin or theme updates are perfect times to use it, as these changes can temporarily break your site’s functionality or appearance. WordPress core upgrades also require maintenance mode, especially when moving between major versions.
Database migrations or repairs are another critical time to use maintenance mode. These operations can make your site unstable or inaccessible while they’re running. Site redesigns benefit from maintenance mode too, allowing you to implement new layouts and features without visitors seeing the work in progress.
When implementing maintenance mode, timing is important. Try to schedule maintenance during low-traffic periods to minimize disruption to your visitors. Keep downtime as short as possible, ideally under 30 minutes for routine updates.
Your maintenance message should be clear and professional. Include information about what’s happening and when visitors can expect the site to be back online. If maintenance will take longer, consider adding contact information or social media links so visitors can stay connected.
Always test your changes on a staging site first if possible. This helps you identify potential issues before they affect your live site. Make sure to backup your site before enabling maintenance mode, especially for major updates.





