put wordpress in maintenance mode quickly

while there may be nice wordpress plugins to put wordpress into maintenance mode, there is also a quick solution. WordPress is notorious for having bloated plugins that may slow down the site… so I love quick and less intrusive solutions.

Just create a an arbitrary file say .maintenance- under the wordpress installation dir. Put this code in the file:


<?php
$upgrading = time() - 1;
?>

When doing maintenance, just rename the file to .maintenance and change it back to the arbitrary filename .maintenance- when done. That’s it.

If you want a custom maintenance page, create the page under /wp-content/maintenance.php

if you want to allow admin to access the site while others see the maintenance mode, use this code:

function is_user_logged_in() {
$loggedin = false;
foreach ( (array) $_COOKIE as $cookie => $value ) {
        if ( stristr($cookie, 'wordpress_logged_in_') )
            $loggedin = true;
    }
    return $loggedin;
}
if ( ! stristr($_SERVER['REQUEST_URI'], '/wp-admin') && ! stristr($_SERVER['REQUEST_URI'], '/wp-login.php') && ! is_user_logged_in() )
    $upgrading = time();

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Sitecritic.net Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.