How To Put Your WordPress Website in Maintenance Mode Without a Plugin

In this tutorial, I will show you how to easily redirect your visitors to a temporary maintenance page without the need of a plugin. The custom maintenance page lets your visitors know that your WordPress Website (or blog) is down for maintenance. Logged-in administrators will still have full access to the Website while visitors see a customized maintenance message.

From time to time you may have to bring down your WordPress Website for maintenance. For instance, If you want to redesign, add new features, change the layout or other significant changes to your Website, then you don´t want your visitors to see your “in progress” changes or broken Web pages. In order to prevent your users from seeing a broken version of your Website, it is crucial that you redirect visitors to a temporary maintenance page.

What about a plugin?

Yes, there are plugins that redirect visitors to a custom maintenance page. But I encourage you to read my previous post about unnecessarily adding plugins to your theme.

There are 2 scenarios when a Website is put into maintenance mode:

  1. Automatic: Executed during an automatic WordPress version update from your dashboard.
  2. Manual: Executed by you at any time you see fit.

1. Automatic Maintenance Mode (Done by WordPress)

When you are performing an automatic WordPress version update from your dashboard, WordPress temporarily puts the Website in maintenance mode until the upgrade is complete.

2. Manual Maintenance Mode (Done at Anytime by You)

The second scenario is when, at a time of your choosing, want to put your Website in maintenance mode. let´s say you are adding custom functionality to your Website and you need an hour to finish the task. This is where you can put your Website into maintenance mode.

Final Result | Manual Maintenance Mode

The picture below shows the temporary maintenance page that your visitors will see, while at the same time logged-in administrators still have full access to the Website.

Example of the WordPress maintenance page.

Features of The “Manual Maintenance Mode” Code

What does my Code do? It adds a maintenance page to your WordPress Website that lets visitors know your Website is down for maintenance. Logged-in administrators (and Super Admins) can continue to work on the Website behind the scene and view those edits online. At the same time, all your visitors and other users only see the maintenance page.

Here are few features of the code:

  1. The code has to be manually activated and deactivated.
  2. Visitors will see a customized, user-friendly maintenance message.
  3. Maintenance message is customizable. You can edit the message as you see fit. For instance, you can specify the time that your Website will be down for maintenance.
  4. Logged-in administrators and Super Admins, get full access to the Website (dashboard/back-end and front-end).
  5. The title of the maintenance page (which also appears on the browser´s tab) is customizable.
  6. Code is tested to work properly on WordPress Version 2.8 and newer.
  7. Code is tested to work properly with all major browsers.

“Manual Maintenance Mode” Code | functions.php

When you are ready to put your Website in Maintenance mode, open the functions.php file located in your theme´s folder, and add (copy and paste) the following code (CODE-1). Your WordPress Website is now NOT available to anyone except administrators.


* @Author: Boutros AbiChedid 
* @Date:   November 14, 2011
* @Websites: ;
* @Description: Function that puts WordPress Website in maintenance mode.
* @Tested on: WordPress version 3.2.1 (but it works on earlier versions.)
function activate_maintenance_mode() {
	//If the current user is NOT an 'Administrator' or NOT 'Super Admin' then display Maintenance Page.
    if ( !(current_user_can( 'administrator' ) ||  current_user_can( 'super admin' ))) {
		//Kill WordPress execution and display HTML maintenance message. 
        wp_die('<h1>Website Under Maintenance</h1><p>Hi, our Website is currently undergoing scheduled maintenance. 
		Please check back very soon.<br /><strong>Sorry for the inconvenience!</strong></p>', 'Maintenance Mode');
//Hooks the 'activate_maintenance_mode' function on to the 'get_header' action.
add_action('get_header', 'activate_maintenance_mode');

CODE-1 Notes:

When you are finished with your Website´s maintenance, make sure to disable maintenance mode by commenting out line 18 of the code. Test to make sure that your Website is back online. No need to remove the code from your functions.php file.

WordPress will not know your role unless you are logged-in to your WordPress dashboard.

If you render your Website in a different browser than where Administrators and Super Admins are logged-in, then the Website will be in maintenance mode. WordPress does not know that you are logged-in in a different browser.

The second parameter of the wp_die() function define the $title variable. This is the HTML title tag of the maintenance page which also appears on the browser´s tab. This is customizable and is better than the default $title variable (´WordPress > Error´). For instance, you can change the $title variable to Your blogname – Maintenance Mode.

wp_die() function accepts some HTML formatting.

CODE-1 works for WordPress 2.8 and above. But I hope that you will upgrade to the latest WordPress version.

Code References:

General Warning

When you add several PHP code blocks in your theme´s funtions.php file, make sure that you do NOT leave any white space (spaces, newline) before the opening PHP tag (<?php) or after the closing PHP tag (?>). The correct way is like so:

//Some Code here beetween the opening PHP tag (above) 
//and the closing PHP tag (below)...
//Some other Code here ...

In the above code, if you leave any white space or a newline between lines 4 and 5, you will get the following error: “Warning: Cannot modify header information - headers already sent by…

HELP! I got stuck in Maintenance Mode. What Should I do?

First don´t panic! It is counter-productive.

  1. If you manually put your wordPress Website in Maintenance mode, using my code (CODE-1), then make sure to go to your functions.php file located in your theme´s folder and comment out line 18 of CODE-1. This will disable the function.
  2. If you were doing an automatic WordPress version update from your WordPress dashboard, then that´s a different and unrelated story. In this case, make sure to manually delete the .maintenance file using your FTP software, then do a manual WordPress upgrade.
    Note that the .maintenance file is located in the root of your WordPress install (same level as wp-settings.php). See the references below for more details.


Your Turn to Talk

At some point, every Website has to perform maintenance of some sort that requires taking the Website offline for sometime. The best way to do that is to keep your visitors informed by redirecting them to a temporary customized maintenance page, and all this without the need of a plugin.

How easy did you find this tutorial to implement? Do you have something to add or anything else to say? If so, please share your opinion in the comments section. Your opinion matters, unless it is a Spam.

If you enjoyed this post, please consider: linking back to it, subscribing by email to future posts, or subscribing to the RSS feed to have new articles delivered to your feed reader. Thanks!

About the Author |
Boutros is a professional Drupal & WordPress developer, Web developer, Web designer, Software Engineer and Blogger. He strives for pixel perfect design, clean robust code, and user-friendly interface. If you have a project in mind and like his work, feel free to contact him. Connect with Boutros on Twitter, and LinkedIn.
Visit Boutros AbiChedid Website.

17 Responses to “How To Put Your WordPress Website in Maintenance Mode Without a Plugin”

  1. geoffrey says:

    I’m just curious, where is the actual page located that the maintenance page uses? I can’t seem to locate it anywhere. Is it a default page that comes with the wp install?

    I use this code and it works great! I would just like to know a little more as to what is going on in the back end.

  2. Onkar says:

    Thanks buddy it works…

  3. andy says:

    How did you get it to style, I tried to add my own class selector in style.css ( I am using my own Theme btw) as such with your function:

    function activate_maintenance_mode() { 
        wp_die('Website Under MaintenanceHi, our Website is currently undergoing scheduled maintenance.
        Please check back very soon.<strong>Sorry for the inconvenience!<strong>', 'Maintenance Mode');   
    • Hi Andy,

      The code I am using has p, strong, br and h1 tags in it. So you can add CSS selectors to the tags (except the strong) or you could just leave it as it is.
      But the code above has all the tags removed except for the strong.
      BTW, If you add my code to your theme. please leave the author section intact (see terms of use).

  4. andy says:

    thanks for this. What if I wanted to have my website still up but take down certain hyperlinks, so that it redirects to this maintenance page.

    • In this case Andy, you don’t need the ‘Maintenance code’. What you could do is have a “maintenance page”, and redirect the specific pages that you want to take temporarily down to that “maintenance page” using .htaccess.
      Use temporary redirection and not a permanent one, for Search Engines sake.
      This tutorial Might help (but I think you need to use 302 instead of 301): 301 Permanent Redirect for an Apache Web Server

  5. trung tran says:

    Thanks for this post
    clearly explained.

  6. Custom Wordpress Theme says:

    Ok that’s very good. I knows only The WordPress Theme system is a way to “skin” your weblog. Yet, it is more than just a “skin.” Skinning your site implies that only the design is changed. WordPress Themes can provide much more control over the look and presentation of the material on your website.I am very new to WordPress and have just started to use it for my design projects.

    At the moment I am just using it for news feeds but I will be using it more and more in the coming months. This is why I am spending time looking at tutorials like this one so it can give me an insight and guide to how I can create certain things in WordPress. I thought this tutorial had great detail and great comments to go along with it.

    This is a tutorial I will be spending time going through and will be a great help in me understanding what WordPress can do for me.

    Tips for Maintenance:
    1) Backup your database and your files. You can use a number of plugins (Backup buddy is a good one) to do this, or if you trust your hosting company, there is often a file and database backup utility within your cpanel.
    2) Update plugins. This one is easy. Go to your plugins and look for any that need to be updated. All you need to do is click the update button and you’re done.
    3) Make sure you have the latest version of WordPress. WordPress will tell you on your dashboard if you need to upgrade. Simply follow the instructions – it’s not difficult.
    4) If you’re not using the akismet plugin, you can get it here – AKISMET . This will protect your site from spam.

  7. Lina Asp says:

    Tried this but nothing happens? The site is still there in full. Is there another step besides putting the code in the functions.php?

    • Lina Asp says:

      OK, so when I erased the first part (the comment part with author etc) it worked fine! Thank you!

      • Hi Lina, you’re not supposed to remove the author part.
        What most likely happened in your case is you didn’t copy the last ‘/’ of the author section which made the whole function as “commented out”.

        • Lina Asp says:

          I copied the whole part but I think my problem was a very slow and not very responsive server, it took almost an hour for my text changes to appear. So I will put back the author part.
          Thank you for sharing such an easy solution to this, I had been searching the net but all the solutions I found first were very complicated.

        • Glad you got it working Lina. When you’re done with putting your Website in Maintenance mode, don’t forget to comment out the function, you could just comment out the hook (just line 18 of CODE-1).

  8. maintenance software says:

    Seriously, I will be forever grateful for this tutorial. Who knew WordPress had a built-in maintenance mode?! Thanks for helping me make my maintenance page look more professional!

  9. fotogtaf nunta says:

    Great piece of advice! I might try this out! Thx

  10. Sam Anderson says:

    Brilliant tutorial and very much inspired to read this article. Great to know about maintaining a wordpress website. Thanks.

  11. Rian Ariona says:

    Thanks Boutros, for this well explained tutorial :)