WordPress maintenance mode

WordPress: Maintenance mode without plugin

WordPress maintenance mode

If you need to keep your website down while you perform an upgrade or solve some problem, there are plenty of WordPress plugins that allow you to activate the maintenance mode and show a “Down for Maintenance” message to visitors. However, you can do this even without adding to the clutter of plugins on your WordPress site.

Add the following snippet to the functions.php file of your WordPress theme and your website will enter the maintenance mode.

You can customize the message to be displayed to your visitors by changing the text in the wp_die function.

When you are done fixing your site and it is ready to welcome visitors again, delete the entire chunk of code or just comment out the last line // add_action();.

// Maintenance Mode - Starts
// Delete the entire chunk of code to disable maintenance mode and make your website live
// Alternatively, comment out the add_action() function by placing two slashes as here

function maintenace_mode() {
      if ( !current_user_can( 'edit_themes' ) || !is_user_logged_in() ) {wp_die('Under Maintenance. The site will be back soon.');}
}
add_action('get_header', 'maintenace_mode');

// Maintenance Mode - Ends