When you need to put your website into maintenance mode for upgrades or when things go wrong and your website is filled with errors you may not want your visitors to visit the website. Until upgrades are done or bugs are fixed, it is better to put it under maintenance mode while having your admin rights intact.
In order to do that without using a plugin, simply paste this code in your functions.php file. After upgrading the website or resolving the errors, delete the line and you are good to go. As always, please do a backup of any file you modify.
// WordPress Maintenance Mode
function wp_maintenance_mode(){
if(!current_user_can(‘edit_themes’) || !is_user_logged_in()){
wp_die(‘<h1 style=”color:blue”>Website under Maintenance</h1><br />We will be back on-line shortly!’);
}
}
add_action(‘get_header’, ‘wp_maintenance_mode’);
If code is “not your thing” use the WP Maintenance Mode plugin available here.