Skip to content
Merlin Tools

Maintenance mode snippet

Close the site to visitors, keep admins in.

Genuinely free. No sign-up, no email, no limits, no cookies. We don't store the URL you analyse.

Code
<?php
// Maintenance mode: shown to non-administrators.
add_action( 'template_redirect', function () {
	if ( current_user_can( 'manage_options' ) || is_admin() ) {
		return;
	}
	wp_die(
		'We\'ll be back shortly.',
		'Maintenance',
		array( 'response' => 503 )
	);
} );

What it's for

During maintenance you want visitors to see a message, not a broken site, while you keep working logged in. This snippet does exactly that, without a plugin, with a correct 503 status code for search engines.

← All WordPress tools

Frequently asked questions

Why does the 503 code matter?

Because it tells search engines «temporarily unavailable»: they won't deindex the site. A common mistake is serving maintenance with a normal 200, which confuses Google.