wordpress snippets last updated   : October 6, 2014
we now have 641 snippets

Maintenance mode without plug-in

wordpress snippet

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(); .

snippet :  PHPcopy
function maintenace_mode() {

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

}
add_action('get_header', 'maintenace_mode');

Did you like this post? If so please share it with your friends. Thanks!

  • Pingback: Tweets that mention Wordpress Maintenance mode without plug-in – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com

  • Ryan

    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?

    • Kevin Chard

      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.

  • Ryan

    I see now, that makes sense :)

    Thanks again.

    • http://wpsnipp.com Kevin Chard

      No problem Ryan glad to help

  • http://twitter.com/andriyleu Andriyleu

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

    • http://wpsnipp.com Kevin Chard

      I sent you a tweet Andriyleu,

  • http://twitter.com/zarylnaxrie zarylnaxrie

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

  • J Hardy

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

    • http://wpsnipp.com Kevin Chard

      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.

  • Serradinho Web Services

    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.

  • Tan

    How can I add a login box for admins?

  • http://redpenredtemper.com/ geraldine| redpenredtemper.com

    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.