New: professional WordPress services from the team behind your theme

Tutorial Maintenance Level: Beginner 10 Minutes

How to Put Your WordPress Site in Read-Only Mode for Migrations and Maintenance

Learn how to put your WordPress site in read-only mode with a small code snippet, so visitors can keep reading while you migrate or maintain your site.

Read-only mode for WordPress: a site that stays online for visitors while logins, comments and registrations are paused

Moving your site to a new host, running a big update or reorganising your content? If someone publishes a post, leaves a comment or places an order while you’re working, that change can easily get lost.

Read-only mode solves this. Your site stays online and visitors can still read every page, but nobody except you can log in or add new content until you’ve finished.

In this tutorial, we’ll show you how to put your WordPress site in read-only mode with a small code snippet, how to pause comments, forms and orders, and how to use read-only mode safely during a site migration.

Read-only mode in WordPress: visitors can still read your site, but logins, comments and registrations are paused for everyone except administrators while you migrate or maintain it

What is read-only mode?

Read-only mode is a temporary state where your WordPress site is still visible, but its content can’t be changed. In practice, that usually means:

  • Visitors can still browse every page and post as normal.
  • Only administrators can log in, so editors, authors and other users can’t make changes.
  • Comments and registrations are paused, so nothing new is added to your database.
  • You stay in control, so you can finish your work and switch read-only mode off again.

WordPress doesn’t have a built-in read-only mode, but you can add one with a few lines of code, as we’ll show below.

When should you use read-only mode?

Read-only mode is useful any time you need your content to stay exactly the same for a while:

  • Site migrations. When you move to a new host, anything added to the old site after your final backup won’t make it to the new one.
  • Major updates. Big plugin, theme or WordPress updates are safer when nobody else is editing.
  • Content restructuring, such as changing categories, permalinks or menus.
  • Database work, such as cleaning up or optimising tables.
  • Security investigations, when you want to stop changes while you check your site.

Read-only mode vs maintenance mode

These two are easy to confuse, but they do different things:

  • Read-only mode keeps your site visible to visitors and only stops changes.
  • Maintenance mode hides your site behind a “back soon” page, so visitors can’t see your content at all.

Use read-only mode when your site is working normally and you just need to freeze content. Use maintenance mode when your site might look broken while you work. Our guide on how to put your WordPress site in maintenance mode explains the other option.

Read-only mode vs maintenance mode in WordPress: read-only mode keeps your site visible and stops changes, while maintenance mode hides the site behind a temporary page

Before you start

  • Take a full backup of your files and database.
  • Tell your team when read-only mode will start and end, so nobody loses work.
  • Make sure you’re an administrator. The snippet below lets administrators log in, but blocks everyone else.
  • Have a way back in. Know how to reach your site’s files through your hosting file manager or FTP, in case you need to switch the snippet off.

Step 1: Add the read-only mode snippet

The easiest way to switch read-only mode on and off is with a small “must-use” plugin. WordPress loads must-use plugins automatically, so there’s nothing to activate.

  1. Connect to your site using your hosting file manager or an FTP client.
  2. Open the wp-content folder. If there’s no mu-plugins folder inside it, create one.
  3. Create a new file called read-only-mode.php inside wp-content/mu-plugins/.
  4. Paste in this code and save the file:
<?php
/**
 * Plugin Name: Read-Only Mode
 * Description: Temporarily stops logins, comments and registrations for everyone except administrators.
 */

defined( 'ABSPATH' ) || exit;

// 1. Only administrators can log in.
add_filter( 'authenticate', function ( $user ) {
    if ( $user instanceof WP_User && ! user_can( $user, 'manage_options' ) ) {
        return new WP_Error(
            'wpi_read_only',
            'The site is in read-only mode for maintenance. Please try again later.'
        );
    }
    return $user;
}, 100 );

// 2. Log out anyone else who is already logged in.
add_action( 'init', function () {
    if ( is_user_logged_in() && ! current_user_can( 'manage_options' ) ) {
        wp_logout();
        wp_safe_redirect( home_url( '/' ) );
        exit;
    }
} );

// 3. Close comments and pings everywhere.
add_filter( 'comments_open', '__return_false', 100 );
add_filter( 'pings_open', '__return_false', 100 );

// 4. Pause new user registrations.
add_filter( 'pre_option_users_can_register', '__return_zero' );

// 5. Remind administrators that read-only mode is on.
add_action( 'admin_notices', function () {
    if ( current_user_can( 'manage_options' ) ) {
        echo '<div class="notice notice-warning"><p><strong>Read-only mode is on.</strong> Only administrators can log in, and comments and registrations are paused.</p></div>';
    }
} );

Make sure the file sits directly inside mu-plugins, not in a subfolder, because WordPress doesn’t load must-use plugins from subfolders automatically. As soon as the file is saved, read-only mode is on. You can also add the same code, without the opening <?php line and the comment block, with a code snippets plugin, then activate or deactivate the snippet to switch read-only mode on and off.

How to add read-only mode to WordPress: open wp-content, create an mu-plugins folder, add a read-only-mode.php file and paste in the snippet

What the read-only mode snippet does

Here’s what each part of the code does:

  1. Only administrators can log in. Anyone else who tries to log in sees a message saying the site is in read-only mode.
  2. Other users are logged out. If an editor or customer is already logged in, they’re logged out the next time they load a page.
  3. Comments and pings are closed on every post and page.
  4. New registrations are paused, even if your site normally lets people register.
  5. Administrators see a reminder at the top of the dashboard, so you don’t forget read-only mode is on.

You can change the login message to suit your site, for example by adding the time you expect to finish.

Step 2: Pause forms, orders and scheduled posts

The snippet stops logins, comments and registrations, but a few other things can still add data to your site. Check these too:

  • Contact forms. Most form plugins still accept submissions. Edit the page to add a short notice, such as “Our contact form is paused until 3 pm. Please email us instead”, or temporarily remove the form.
  • Online store orders. Guests may still be able to check out. If you run a store, pause checkout or put the store in a catalogue-only mode while you work, and show a notice to shoppers.
  • Scheduled posts. WordPress will still publish posts scheduled for that time. Reschedule them for after your maintenance window.
  • Automated tasks. Plugins may still run scheduled jobs, such as imports or email digests. Pause any that write to your database.
Before you freeze your WordPress site: pause contact forms, store checkout, scheduled posts and automated tasks that can still add data

Step 3: Test read-only mode

Before you start your work, check that read-only mode is working:

  1. Open a private browser window and visit your site. It should look normal.
  2. Try to leave a comment. The comment form should be gone or closed.
  3. Try to log in as a non-administrator, such as a test editor account. You should see the read-only message.
  4. Check your dashboard as an administrator. You should see the yellow “Read-only mode is on” notice.

Using read-only mode during a site migration

Read-only mode is especially useful when moving your site to a new host. Here’s a safe order to follow:

  1. Switch on read-only mode on your old site.
  2. Take a final backup of your files and database.
  3. Copy the site to your new host.
  4. Test the new site thoroughly before you change your domain’s DNS.
  5. Point your domain to the new host.
  6. Switch off read-only mode on the new site once it’s live.

Don’t forget: because the read-only-mode.php file is inside wp-content, it gets copied to your new host along with everything else. Remember to remove it from the new site, or your team won’t be able to log in.

While the DNS change spreads across the internet, some visitors may still see your old site for a while. Keeping read-only mode on the old site means nothing new is added there by mistake.

How to use read-only mode for a WordPress migration: switch it on, take a final backup, copy the site, test it, point your domain and switch it off on the new site

Step 4: Switch read-only mode off

When you’ve finished, turn read-only mode off:

  1. Delete the read-only-mode.php file from wp-content/mu-plugins/, or rename it to something like read-only-mode.php.off. If you used a code snippets plugin, deactivate the snippet.
  2. Re-enable your forms and checkout, and remove any notices you added.
  3. Reschedule any posts you moved.
  4. Let your team know they can log in again.

Tips for a smooth maintenance window

  • Pick a quiet time. Check your analytics to find when you get the fewest visitors.
  • Keep it short. Plan your work in advance, so read-only mode is only on for as long as you need it.
  • Watch your site. An uptime monitor tells you straight away if something goes wrong. Our guide on uptime monitoring for WordPress shows you how to set one up.
  • Have a rollback plan. If an update goes wrong, our guide on rolling back a WordPress update that broke your site can help.
  • Keep a backup copy offsite. Our guide on how to back up WordPress to Dropbox shows you one way.

Lightweight WPInterface themes

A fast, lightweight theme makes migrations and updates easier, because there’s less to move and less that can go wrong. WPInterface Pro themes are built with lean code, translation ready and RTL compliant.

Business Interface Pro

Business Interface Pro is a lightweight multipurpose business theme with 12 starter sites, ideal for company websites that need to be fast and professional.

Business Interface Pro lightweight WordPress business theme demo screenshot

SpeedNews Pro

SpeedNews Pro is a fast news and magazine theme with a trending ticker, mosaic headlines and three-column layouts, built for publishing teams who post every day.

SpeedNews Pro fast WordPress news theme demo screenshot

BlogNest Pro

BlogNest Pro is a modern, elegant blog theme for bloggers and content creators, with a post slider, Featured Categories and spotlight blocks.

BlogNest Pro elegant WordPress blog theme demo screenshot

You can see all our themes on the WordPress themes page.

Need a hand?

If you’d rather not handle a migration or maintenance yourself, the WPInterface team can help:

Frequently asked questions

Does WordPress have a built-in read-only mode?

No. WordPress has a maintenance mode it uses briefly during updates, but no read-only mode. You can add one with the code snippet in this guide.

Will read-only mode affect my SEO?

Your site stays online and your pages load normally, so search engines can still crawl them. For a short maintenance window, read-only mode shouldn’t affect your rankings.

Can visitors still see my site in read-only mode?

Yes. Visitors can browse your site as normal. They just can’t log in, comment or register.

What happens if I lock myself out?

The snippet always lets administrators log in. If something goes wrong, delete or rename the read-only-mode.php file in wp-content/mu-plugins/ using your hosting file manager or FTP.

Does read-only mode stop all database changes?

No. It stops logins, comments and registrations, but administrators, plugins, forms, store checkouts and scheduled tasks can still make changes. Pause these separately, as described above.

Should I use read-only mode or maintenance mode for a migration?

Read-only mode is usually better, because your site stays online for visitors while you work. Use maintenance mode if your site might look broken during the work.

Final thoughts

Read-only mode is a simple way to protect your content during migrations and maintenance. Your visitors can still read your site, while you make sure nothing is added or changed until you’re ready.

Add the snippet, pause your forms and scheduled posts, test it, and remember to switch it off, especially on your new host after a migration.

Reactions

How did this make you feel?

Be the first to react

One reaction per visitor. Tap again to change or remove it.

Keep reading

Browse all resources

Discussion

Leave a reply

Your email address stays private. Required fields are marked *