How to Add Quick Maintenance Mode to WordPress

Posted by Lasantha Bandara on July 17th, 2015 File Under : wordpress0 Comment

Need to add a maintenance page to a WordPress website that lets visitors know your blog is down for maintenance? There are more plugins to do this task for you. But actually you can do this without installing any plugin to your website. It will simply display for error message for site visitors, but users with admin rights gets full access to the site front-end and back-end. Add this code into your theme's functions.php file:

function btt_maintenance_mode() {
    if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {
        wp_die('<h1>Temporarily Down For Maintenance</h1><p>We are performing scheduled maintenance. We should be back online shortly.</p>', 'Maintenance');
    }
}
add_action('get_header', 'btt_maintenance_mode');

Now when a visitor (non-administrator) trying to access into the website, this message will be displayed to them:

Maintenance Mode for WordPress

After finishing maintenance tasks, remove above code from the functions.php file to open your website for visitors again.

File Under : wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.