Activate WordPress maintenance mode without a plugin

Do you want to put your WordPress website in maintenance mode while you make some changes to the website without a plugin? Use this code snippet to do just that.

Add the following code snippet to your theme’s funtion.php file.

// 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');

Code not working? Contact us to let us know.