
Putting Your WordPress Site in Maintenance Mode
- May 30, 2017
- Leave a comment
WordPress provides a feature of maintenance mode that blocks the access and halts the functions during updates. In order to put your website under maintenance mode, you need to create a temporary page with a custom message on it. This will let your website visitors know that your site is down for maintenance.
To create a temporary page with a custom message, you need to follow the steps mentioned below:
- Create a maintenance.php file
- Add the custom message in maintenance.php file
- Using <style> tag, apply styling (Theme styling is recommended)
- Place the maintenance file in /wp-content folder
- Add the following code in your Theme‘s functions.php file:
12345678910111213141516add_action( 'wp_loaded', function() {global $pagenow;if(defined( 'IN_MAINTENANCE' )&& IN_MAINTENANCE&& $pagenow !== 'wp-login.php'&& ! is_user_logged_in()) {header( 'HTTP/1.1 Service Unavailable', true, 503 );header( 'Content-Type: text/html; charset=utf-8' );if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {require_once( WP_CONTENT_DIR . '/maintenance.php' );}die();}}); - Add the following code in wp-config.php file to enable/disable the maintenance mode:
1define('IN_MAINTENANCE', true);
You are done! Now, check your website URL. You will be redirected to a temporary page containing the custom message that your site is down for maintenance.
Great Article!
Thanks
Informative post…I totally agree with the sentence “Putting Your WordPress Site In Maintenance Mode”.