The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Add a Custom Maintenance Mode Message in WordPress

Shared by Amit Dholiya · October 24, 2026

7 views
1 upvote
Back to Snippets

Steps

  1. Add the complete PHP code to your child theme’s functions.php file or a PHP snippets plugin.

  2. Activate the snippet.

  3. Test the site in a logged-out browser or as a non-administrator.

Hook Used

– template_redirect — Runs before WordPress chooses and loads the front-end template.

Type: WordPress Website Maintenance

Output: Visitors who are not administrators see a maintenance message with an HTTP 503 response. Administrators with the manage_options capability can still access the site.

Important: Disable the snippet when maintenance is complete.

function custom_maintenance_mode_message() {
    if ( ! current_user_can( 'manage_options' ) ) {
        wp_die(
            '<h1>We’ll Be Back Soon!</h1>
            <p>Our website is currently undergoing scheduled maintenance.</p>
            <p>Please check back shortly. Thank you for your patience!</p>',
            'Scheduled Maintenance',
            array( 'response' => 503 )
        );
    }
}
add_action( 'template_redirect', 'custom_maintenance_mode_message' );

Tested on

WordPress 6.8

Reported by the author on October 24, 2026. WPFolks has not verified this.

Not tested against WordPress 7.1.4. It may still work.

Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments

Proudly supported by