# Maintenance Mode for Visitors

> Shows a "back soon" message with a 503 status to visitors while logged-in staff browse the site normally. The login page stays reachable.

- Type: PHP
- Runs: Frontend only
- Category: [Redirects](https://wpide.com/library/category/redirects/)
- Tags: maintenance, coming-soon, 503
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/maintenance-mode/

## Code

```php
add_action( 'template_redirect', function () {
    if ( current_user_can( 'edit_posts' ) ) {
        return;
    }

    if ( ! headers_sent() ) {
        header( 'Retry-After: 3600' );
    }

    wp_die(
        '<h1>We&rsquo;ll be right back</h1><p>The site is undergoing scheduled maintenance. Please check back soon.</p>',
        esc_html( get_bloginfo( 'name' ) ) . ' - Maintenance',
        array( 'response' => 503 )
    );
} );
```

## Notes

Remember to deactivate the snippet when maintenance is over.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Maintenance Mode for Visitors" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
