Quick And Easy WordPress Maintenance Mode

Today quick script to put your wordpress site in maintenance mode.
Just paste the code that in functions.php and only logged in user will see the front end of the site:

<?php
/***************************************************************************
* @Author: Boutros AbiChedid
* @Date: November 14, 2011
* @Websites: http://bacsoftwareconsulting.com/ ; http://blueoliveonline.com/
* @Description: Function that puts WordPress Website in maintenance mode.
* @Tested on: WordPress version 3.2.1 (but it works on earlier versions.)
****************************************************************************/
function activate_maintenance_mode() {
//If the current user is NOT an 'Administrator' or NOT 'Super Admin' then display Maintenance Page.
if ( !(current_user_can( 'administrator' ) || current_user_can( 'super admin' ))) {
//Kill WordPress execution and display HTML maintenance message.
wp_die('<h1>Website Under Maintenance</h1><p>Hi, our Website is currently undergoing scheduled maintenance.
Please check back very soon.<br /><strong>Sorry for the inconvenience!</strong></p>', 'Maintenance Mode');
}
}
//Hooks the 'activate_maintenance_mode' function on to the 'get_header' action.
add_action('get_header', 'activate_maintenance_mode');
?>

Thanks to http://bacsoftwareconsulting.com

Divi 2.0 WordPress Theme

Like what you read here in this blog post? If yes, please sign up and get latest articles delivered to your email account for FREE! You’ll be also subscribed to newsletter, where I share a exclusive content and offers.

About Kris Hoja

Hi! I'm Kris. For a while I was blogging about WordPress, now I'm owner of HogStudio - Creative Agency focused on website development.
Add me on Google+ and don't forget to follow me on Twitter :)

Leave a Reply