How to put WordPress in maintenance mode without a plugin
The SnipCraft team
You don’t need a dedicated plugin to put WordPress into maintenance mode. A small snippet shows visitors a holding page while you keep full access to the admin. It also does the one thing most DIY versions get wrong: it returns the correct HTTP status for search engines.
The snippet
This intercepts front-end requests early, lets administrators (and CLI/cron) through, and shows everyone else a maintenance page:
<?php
add_action( 'template_redirect', 'scseed_maintenance_mode', 1 );
function scseed_maintenance_mode() {
// Allow administrators, CLI processes, and WP-Cron through.
if ( current_user_can( 'manage_options' ) ) {
return;
}
if ( defined( 'WP_CLI' ) && WP_CLI ) {
return;
}
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
return;
}
// 503 tells search engines the site is temporarily unavailable.
status_header( 503 );
header( 'Retry-After: 3600' );
nocache_headers();
$site_name = get_bloginfo( 'name' );
wp_die(
'<div style="font-family:sans-serif;text-align:center;padding:60px 20px;">'
. '<h1>' . esc_html__( 'Briefly unavailable for scheduled maintenance.', 'scseed' ) . '</h1>'
. '<p>' . esc_html__( 'Check back in a moment.', 'scseed' ) . '</p>'
. '<p style="color:#888;font-size:0.9em;">' . esc_html( $site_name ) . '</p>'
. '</div>',
esc_html__( 'Maintenance Mode', 'scseed' ),
array( 'response' => 503 )
);
}The detail that matters for SEO
The key line is status_header( 503 ). A 503 Service Unavailable with a Retry-After header tells Google the downtime is temporary, so it doesn’t deindex your pages. Naive maintenance snippets return a normal 200 with a “we’ll be back” page, which can look like your real content has vanished. Always send a 503.
How it works
Hooking template_redirect at priority 1 runs before the theme renders, so no page content leaks out. The capability check (manage_options) means you can keep working in wp-admin and preview the live site while visitors see the holding page.
Important
Because a fatal error in a maintenance snippet could lock you out of your own site, run it under a manager with safe mode. The SnipCraft version is here. Enable it, flip it off when you’re done, no file edits.