How to Put Your WordPress Site to Maintenance Mode Without Plugin

Snippets by IsItWP

Are you looking for a way to put your WordPress into maintenance mode? While there’s probably a plugin for this, we have created a quick code snippet that you can use to put your WordPress site to maintenance mode without plugin.


All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

function maintenance_mode() {

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

add_action('get_header', 'maintenance_mode');

To disable the maintenance mode and allow users to access to your website, simply comment out the last line like this:

// add_action();

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 19 best WordPress plugins for non-profits and how to create stunning WordPress optin forms.

Comments  Leave a Reply

  1. Excellent, it work as a charm, there is one little typo tho, it should say maintenance_mode rather than maintennce_mode. I am really greatly this functionality works great with no plugin.

    1. Glad to be of help, Donald

  2. I gave the code a go on a test site and it worked beautifully.

    I looked up the wp_die() function and I saw it could take more parameters. That’s necessary because, at the time of the test, the page title was “WordPress – Error” and I was wondering how to change that, so I did this instead: wp_die(‘Hello, the site is undergoing some minor maintenance at the moment, please check back later.’, ‘Site Under Maintenance’.)

    So instead of seeing the default page title, I had “Site Under Maintenance” which I think it a lot better than seeing the “Error” word. The first argument (the message part) also accepts HTML, so you can add links and formatting if you’d like.

    Just wanted to share, and thank you so much Saha!

  3. Probably the best no-plugin solution. Also much better than mucking around with root folders and hidden files as other tutorials touch on.

    1. Glad you find it useful

    2. Agreed!

      I usually prefer using custom code over plugins whenever I can and I really like this one!

  4. 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.

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

  6. 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.

  7. 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.

  8. 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

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

    1. I sent you a tweet Andriyleu,

  10. I see now, that makes sense 🙂

    Thanks again.

    1. No problem Ryan glad to help

  11. 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.

  12. 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 Cancel reply

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!
[60% OFF Today!]
[60% OFF Today!]
[10% OFF Today!]
[10% OFF Today!]
[50% OFF Today!]
[50% OFF Today!]