Maintenance mode
Visitors see a simple “Back soon” page (with the proper 503 status for search engines) while you work. Logged-in editors see the site as usual.
Before you switch it on: Write your own message in $message. Switch the snippet off when you’re done.
It arrives switched off, even when you install its whole pack with "Switch on after installing".
<?php
add_action(
'template_redirect',
static function () {
if ( current_user_can( 'edit_posts' ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
return;
}
$message = 'We’re updating the site and will be back within the hour.';
header( 'Retry-After: 3600' );
wp_die(
'<h1>' . esc_html( get_bloginfo( 'name' ) ) . '</h1><p>' . esc_html( $message ) . '</p>',
esc_html( get_bloginfo( 'name' ) ),
array( 'response' => 503 )
);
},
0
);
Good to know
The login page, the admin area and the REST API keep working. Page caches may keep showing the normal page: clear them after switching this on.
In these packs
- Developer tools: Maintenance mode, template names, page stats, environment labels and a WP-Cron viewer.