Maintenance Mode For WordPress

November 30, 2011 — Leave a comment

How to put WordPress into “Maintenance Mode”

How to put WordPress into "Maintenance Mode"

One thing that many people don’t know about WordPress is that it comes with the built-in ability to put itself into “Maintenance Mode”. This can come in super handy while you’re developing, switching, upgrading, or troubleshooting your WordPress site. It will give you (or any user with the ability to sign into the admin area of WordPress) the ability to sign into WordPress and see your site as you normally would while your visitors / users see a completely separate splash page or even a completely different site. For the sake of this tutorial, we’ll just stick to a splash page.

Below are the steps to put WordPress into, and easily get it out of, “Maintenance Mode”. For this tutorial, you’ll need to make sure that you can see / edit hidden files (files that begin with a “.”) in your file system or FTP client.

1.  Create a .maintenance file and put it in the root directory of your WordPress install.

2.  Add the following code to the .maintenance file. This will allow any user logged into the admin panel of WordPress to actively access the front-end of the website while non-admin visitors will see your page / site in the next step.

<?php 
    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(); 
    } 
    else 
    { 
        $upgrading = 0; 
    } 
?>

3.  Create a maintenance.php file and put it in the wp-content folder. The maintenance.php file can be styled and laid-out however you want like any traditional HTMNL / PHP “splash” page.  **Note: If you’re using images and relative file paths in your maintenance.php file, you should know that the maintenance.php will start looking from the root of your website and not wp-content or your current theme’s root.

4.  To take WordPress out of “Maintenance Mode”, simply rename .maintenance to !maintenance to turn maintenance mode off (and vice-versa to turn it back on) while leaving all other files in place. This “toggling” of the filename gives you the ability to save doing this all over again next time.

You can also make changes to the look of the maintenance screen. For instance, if you want to change the background you can can simply use:

body { background: url('LINK_TO_IMAGE'); }


josh

Posts Twitter Facebook

I'm Josh, a principal founder @ Run Level Media , a web dev and internet strategy consulting firm in Atlanta, GA. I enjoy anything web, mobile, tech, gaming, golf and craft beers. I look forward to connecting with you.

No Comments

Be the first to start the conversation.

Leave a Reply

*

Text formatting is available via select HTML. <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Have you Subscribed via RSS yet? Don't miss a post!