Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Are you asking how to use a theme template as your maintenance page? –  totels Dec 12 '12 at 2:17
add comment

1 Answer 1

When WordPress goes into maintenance mode, it adds a file named .maintenance to the wordpress directory while the maintenance is being performed, then it's removed afterwards.

You can write a function inside your theme's functions.php that checks for this file and goes to your theme's maintenance page.

Here's how I did it:

if ( ! function_exists( 'sx84987_maintenance_mode' ) ) :
    function sx84987_maintenance_mode() {
        if ( file_exists( ABSPATH . '.maintenance' ) ) {
            include_once( get_stylesheet_directory() . '/maintenance.php' );
                die();
        }
    }
    add_action( 'wp', 'sx84987_maintenance_mode' );
endif;

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.