Post

Put WordPress into maintenance mode

One of the best features of Wordpress is how customisable it is. There are so many plugins that allow you to customise your Wordpress site.

However, Its much nicer to be able to do stuff in Wordpress without using a plugin.

One such task is putting it into maintenance mode. Granted, it’s not something you have to do often. But when you do you can use a snippet rather then a plugin.

Activate WordPress Maintenance Mode

Here we are using an action to put WordPress into maintenance mode. First the script checks to see if the user is not logged in. Add to functions.php

1
2
3
4
5
6
7
// Activate WordPress Maintenance Mode
function wp_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', 'wp_maintenance_mode');
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.