Is there a way to add a custom maintenance page from theme folder?
I have the code for the activate maintenance mode but i can’t get the styling..
function activate_maintenance_mode() {
if ( !(current_user_can( 'administrator' ) || current_user_can( 'super admin' ))) {
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');
}
}
add_action('get_header', 'activate_maintenance_mode');
Thanks in advance,
Nikola.
When WordPress goes into maintenance mode, it adds a file named
.maintenance
to the root directory while the maintenance is being performed, then it’s removed afterwards. You can write a function inside your theme’sfunctions.php
that checks for this file and loads a custom maintenance page from the theme.Put your maintenance content in the
maintenance.php
page inside your theme folder and you’re all set to style it however you would like.If you use the
wp_die
function, you’ll get the standard white box on grey background. This way lets you style your maintenance page like you would any other theme page.UPDATE: You can also do this outside the theme by adding
maintenance.php
to thewp-content
directory (or wherever you’ve setWP_CONTENT_DIR
to point to) as a drop-in plugin. When WP checks for maintenance mode from insidewp_maintenance()
it’ll look for that file and load it if present, or load its own if not. If the site isn’t in maintenance mode, or is in it for more than 10 minutes, ‘maintenance.php’ won’t load even though the site is technically still in maintenance mode. WordPress 4.6 introduces the ‘enable_maintenance_mode’ filter, which can be (ab)used by a tool likewp-cli
to force the check for the drop-in and would let you run a CLI command from your maintenance file.