Activate WordPress maintenance mode

Do you want to put WordPress in maintenance mode while you make some changes to the website without a plugin? You can do so with the following snippet.

// Activate WordPress Maintenance Mode
function activate_maintenance_mode() {
    if (!current_user_can('edit_themes') || !is_user_logged_in()) {
        wp_die('<h1>Under Maintenance</h1><br />Website under planned maintenance. Please check back later.');
    }
}
add_action('get_header', 'activate_maintenance_mode');

– LAST TESTED DECEMBER 9, 2019

Code not working? Let us know in the comments below.

Latest Snippets

Leave a comment