Maintenance mode without plug-in

Undo changes with history in CSS Hero

Adding this snippet to the functions.php of your wordpress theme will put your wordpress website into Maintenance mode. To disable this snippet and allow people to access your website again, just comment out the last line // add_action(); .

function maintenace_mode() {

      if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {wp_die('Maintenance.');}

add_action('get_header', 'maintenace_mode');

Comments  Leave a Reply

  1. geraldine| redpenredtemper.com June 27, 2013 at 10:44 am

    Thanks for the snippet! This one works for my blog! 🙂 Just the code I’m
    looking for since I don’t want to install maintenance plugin.

  2. How can I add a login box for admins?

  3. Serradinho Web Services March 28, 2012 at 6:24 am

    This is a nice code snippet, but it’s not really user friendly as user will have to edit functions file. I have taken the above as a basis and creating my own admin page with select dropdowns and textarea for information.

  4. can you use this and make it load a custom maintenance page within the theme?

    1. I’m sure you can, I use wp_die() and that kills the execution and displays and error message. But you could have the snippet redirect or since it hijacks the get_header you could give it HTML for a special page you wish to load.

  5. maintenance or maintenace? is it typing error or it’s just me as another WordPress newbie?

    1. Hi zarylnaxrie its not an error its like this plugin but without the need to install one. Just add the code to your functions.php

  6. Kevin, I loved you old wp theme, can you send me it?

    1. I sent you a tweet Andriyleu,

  7. I see now, that makes sense 🙂

    Thanks again.

    1. No problem Ryan glad to help

  8. The last time I tried the built in maintenance mode I was blocked from the admin too, even with an admin account. Will this still be the case?

    1. Hi Ryan,
      You should be fine with this maintenance mode, In fact I use a similar plug-in. Keep in mind you will need to go right to the login page to access the admin. yoursite.com/wp-admin/ should get you in or yoursite.com/wp-login.php

      If you notice this sample has the code
      if ( !current_user_can( ‘edit_themes’ ) || !is_user_logged_in() )
      if the user can’t edit themes or is not logged in then display the maintenance mode message. This should work the same way for any plug-in.

      I should note that if you ever get stuck you can always login with FTP and delete the plug-in or in the case of this snippet download and remove it from functions.php and upload the updated functions.php if you have any problems.

  9. Tweets that mention Wordpress Maintenance mode without plug-in – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com February 23, 2011 at 10:13 am

    […] This post was mentioned on Twitter by wp_freak, WPSNIPP. WPSNIPP said: #wordpress Maintenance mode without plug-in http://bit.ly/i7OtNK #blog please RT 🙂 […]

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!