wp_maintenance()WP 3.0.0

Die with a maintenance message when conditions are met.

The default message can be replaced by using a drop-in (maintenance.php in the wp-content directory).

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.


null. Nothing (null).





#1 Putting the site into maintenance mode (updates, development)

When updating code on the site, it is recommended to put the site in maintenance mode (block for the duration of the update), so that sudden visits from users could not affect the process of updating files or DB.

To enable such a mode you need:

Option 1:

Create file .maintenance in the root of the site (directory where wp-admin folder is located) with the following code:

// UNIX time stamp after which + 10 minutes,
// the site will exit development mode.
$upgrading = 1652995051; // time();

Option 2:

Create an empty file ABSPATH . '.maintenance' and manually at an early stage, for example in the wp-config.php file specify a global variable $upgrading:

// UNIX time stamp after which + 10 minutes,
// the site will exit development mode.
$GLOBALS['upgrading'] = 1652995051; // time();


Refresh the page and see the maintenance message:

The site is briefly closed for maintenance. Come back in a minute.


#2 Let's change the text of the maintenance message:

Create a file /wp-content/maintenance.php with following code:


$protocol = $_SERVER["SERVER_PROTOCOL"];
if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ){
	$protocol = 'HTTP/1.0';
header( "$protocol 503 Service Unavailable", true, 503 );
header( 'Content-Type: text/html; charset=utf-8' );
header( 'Retry-After: 600' );

// most WP functions do not work

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<div style="max-width:800px; margin:50px auto; text-align:center;">
		<h1>Site is under maintenance. The correct work will be restored in a few minutes.</h1>
		<h2>Sorry for the inconvenience.</h2>

When the site is updated, our message about the inaccessibility of the site will be changed and we will see the text specified above.


#3 Function to enable or disable maintenance mode

There is no such feature in WordPress by default. So let's write our own function that will allow us to conveniently enable and disable the maintenance (service) mode of the site:

 * Enables or Disables the WP maintenance mode.
 * @param string $action 'on' | 'off'
 * @return void
function wpkama_wp_maintenance_mode( $action = 'on' ){
	global $wp_filesystem;

	if( ! $wp_filesystem ){
		require_once ABSPATH . 'wp-admin/includes/file.php';


		if ( 'direct' !== $wp_filesystem->method ) {
			/** @noinspection ForgottenDebugOutputInspection */
			wp_die( 'WP_Filesystem need to be direct type.' );

	$maintenance_file = $wp_filesystem->abspath() . '.maintenance';

	// Create maintenance file to signal that we are upgrading.
	if( 'on' === $action ){
		$maintenance_string = sprintf( '<?php $upgrading = %d; ?>', time() );

		$wp_filesystem->delete( $maintenance_file );
		$wp_filesystem->put_contents( $maintenance_file, $maintenance_string );
	// Remove maintenance file, we're done with potential site-breaking changes.
	else {
		$wp_filesystem->delete( $maintenance_file );


An example of the use of the function:

wpkama_wp_maintenance_mode( 'on' );

sleep(6); // simulate some actions

wpkama_wp_maintenance_mode( 'off' );


Since 3.0.0 Introduced.

wp_maintenance() code WP 6.5.3

function wp_maintenance() {
	// Return if maintenance mode is disabled.
	if ( ! wp_is_maintenance_mode() ) {

	if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
		require_once WP_CONTENT_DIR . '/maintenance.php';

	require_once ABSPATH . WPINC . '/functions.php';

	header( 'Retry-After: 600' );

		__( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ),
		__( 'Maintenance' ),