How to Enable Maintenance Mode in WordPress

When performing updates or changes to your WordPress site, it's essential to inform visitors that the site is temporarily unavailable. While many plugins can handle this, you can manually enable maintenance mode by adding a custom PHP snippet to your theme. This allows for greater control and flexibility.

The following code can be added to your theme's functions.php file to enable maintenance mode for non-admin users, while still allowing administrators and critical processes (like AJAX requests, cron jobs, and REST API calls) to function normally.

function themesdna_maintenance_mode() {
    // Allow access for admins and specific non-front-end requests
    if ( current_user_can( 'manage_options' ) || is_admin() || wp_doing_ajax() || wp_doing_cron() || defined( 'REST_REQUEST' ) && REST_REQUEST ) {
        return; // Allow access for admin, AJAX, CRON, or REST requests
    }

    // Maintenance mode message
    $maintenance_message = '<h1>Maintenance Mode</h1><p>We are performing scheduled maintenance. Please check back soon.</p>';

    // Output the maintenance mode message for non-admin users
    wp_die( $maintenance_message, 'Maintenance Mode', array( 'response' => 503 ) );
}

// Enable Maintenance Mode for non-admin users
add_action( 'template_redirect', 'themesdna_maintenance_mode' );

By using this code, you can control exactly who sees the maintenance page and ensure your site remains operational behind the scenes while you perform updates.

Our WordPress Themes

Below are some of our premium WordPress themes. View all our free and premium WordPress themes →
Simple Writer PRO WordPress Theme

Simple Writer PRO

Simple Writer PRO is a feature-rich, improved and advanced version of Simple Writer Free WordPress Theme. When compare with the...

$25.00
GridLane PRO WordPress Theme

GridLane PRO

If you like the free version of GridLane WordPress Theme, you'll love the premium version even more. It will help...

$25.00
GridHot PRO WordPress Theme

GridHot PRO

If you have tried GridHot Free WordPress Theme, then you will love the premium version. GridHot PRO version has color...

$25.00
GridMini PRO WordPress Theme

GridMini PRO

Do you like the free version of the GridMini WordPress theme? But what if you need more features and options?...

$25.00
MagPal PRO WordPress Theme

MagPal PRO

$25.00
RapidWP PRO WordPress Theme

RapidWP PRO

Did you try RapidWP Free WordPress Theme?, Then you will love the premium version. RapidWP PRO is an improved, more...

$25.00
GridRead PRO WordPress Theme

GridRead PRO

If you like GridRead Free WordPress Theme, then you will love the premium version. GridRead PRO version has color options,...

$25.00
GridMag PRO WordPress Theme

GridMag PRO

If you like GridMag free WordPress Theme, you will love the premium version. GridMag PRO is an improved version of...

$25.00

Can't you choose a single theme? Purchase All Themes for $75.

Save money with our low, one-time price for access to all of our 56 WordPress themes.