← Back to blog

How to make a WordPress site private, and the parts a login wall leaves open

The SandyWP team 8 min read

To make a WordPress site private, send every logged-out visitor to the login page, then make the REST API refuse logged-out requests as well. A plugin such as My Private Site does the first part, and a short mu-plugin does both.

What neither does is protect your uploads, and the setting most people reach for first, Settings, Reading, Discourage search engines, does not make anything private at all. This guide covers what each method actually blocks, checked against the WordPress 7.1.5 source, and how to test it from a logged-out terminal.

Which method should I use?

Goal Method Blocks visitors? Blocks /wp-json/? Blocks uploads?
Keep it out of Google Discourage search engines No No No
Show a holding page before launch Coming soon plugin Pages only Depends on the plugin No
Only logged-in users see anything Login-wall plugin or mu-plugin Yes Only if you add it No
Nothing leaves the server without a password HTTP basic auth Yes Yes Yes

For a family blog, an intranet or a client site under construction, the login wall is usually right. If the files themselves are sensitive, you need the server-level option, and it has costs covered below.

Does "Discourage search engines" make a site private?

No. WordPress says so on the same screen: "Neither of these options blocks access to your site, it is up to search engines to honor your request."

With the box ticked (blog_public set to 0), WordPress adds <meta name='robots' content='noindex, nofollow'> to every page and switches off the built-in XML sitemap. It does not change robots.txt, and every page still loads for anyone with the URL.

Keep it ticked on a private site anyway. If something does leak, it is at least marked noindex.

How do I make a whole WordPress site require login?

The plugin route is My Private Site (10,000+ active installs on wordpress.org, version 4.2.3 when we checked). Install it, open My Private Site, Site Privacy, tick Enable login privacy and save.

Its wordpress.org page lists an option to "block unauthenticated access to the WordPress REST API". Turn it on: it is optional, and that is the part most guides skip.

Without a plugin, put this in wp-content/mu-plugins/private-site.php. An mu-plugin loads on every request and cannot be switched off from the Plugins screen, which is what you want for an access rule.

<?php
// Send logged-out visitors to the login page.
add_action( 'template_redirect', function () {
	if ( is_user_logged_in() ) {
		return;
	}
	nocache_headers();
	$here = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
	wp_safe_redirect( wp_login_url( $here ) );
	exit;
}, 1 );

// Refuse REST API requests from logged-out visitors.
add_filter( 'rest_authentication_errors', function ( $result ) {
	if ( true === $result || is_wp_error( $result ) ) {
		return $result;
	}
	if ( ! is_user_logged_in() ) {
		return new WP_Error( 'rest_not_logged_in', 'You are not currently logged in.', array( 'status' => 401 ) );
	}
	return $result;
} );

Priority 1 runs the redirect before core's own template_redirect work, including the sitemap renderer at priority 10. Feeds and robots.txt are handled after template_redirect fires, so the redirect covers them too.

Do not reach for auth_redirect() here, even though it looks made for the job. It checks the auth cookie, which WordPress only sends to /wp-admin/ and the plugins path, so on a front-end URL it treats a logged-in user as logged out and loops them back to the login page.

Then give people accounts under Users, Add New with the Subscriber role, and leave Settings, General, Anyone can register unticked. If registration is open, the login page is also a sign-up page, and the wall lets in anyone who fills it in.

Why can logged-out visitors still read posts at /wp-json/?

Because the REST API answers before the redirect ever runs. WordPress serves /wp-json/ from the parse_request action and calls die() when it is done, so the wp and template_redirect hooks never fire for that request.

The snippets most ranking guides offer hook into one of those two. On those sites, this still returns every published post, in full, to anyone:

curl -s https://example.com/wp-json/wp/v2/posts | head -c 400

The same applies to pages, media items, and the authors of published posts at /wp-json/wp/v2/users (our post on WordPress user enumeration covers that endpoint).

The fix is the rest_authentication_errors filter in the snippet above. Do not disable the REST API outright: the REST API handbook says "You should not disable the REST API; doing so will break WordPress Admin functionality", and the block editor saves through it.

Are images and uploads private on a private site?

No, and no WordPress-level method can change that. Files in wp-content/uploads are served by the web server directly, so PHP never runs, and no plugin hook gets a chance to check who is asking.

My Private Site says this plainly in its limits: it "won't restrict images and other media and text files directly accessed by their URL." An uploaded PDF on a private site is one shared link away from being public.

If the files matter, protect them at the server, which is the next section.

What else stays reachable behind a login wall?

Even with the mu-plugin above, a few entry points never go through template_redirect:

  • wp-login.php, by design. It has to load for anyone to log in.
  • xmlrpc.php, which has its own front door. Our XML-RPC post covers what it accepts without a login and how to close it.
  • admin-ajax.php actions registered with wp_ajax_nopriv_. Core registers two (heartbeat and generate-password), and contact forms, search and filter plugins often add their own.
  • Cached pages. A full-page cache serves stored HTML from advanced-cache.php before WordPress decides who you are. Purge it after you switch the wall on, or logged-out visitors keep getting yesterday's public copy (see clearing every WordPress cache).

Should I use HTTP basic auth instead?

It is the only method that covers everything, uploads included, because the web server asks for the password before WordPress or the file is touched. On Apache, it looks like this in .htaccess, with the password file kept outside the web root:

AuthType Basic
AuthName "Private site"
AuthUserFile /home/example/.htpasswd
Require valid-user

<Files "wp-cron.php">
	Require all granted
</Files>

Create the password file with htpasswd -c /home/example/.htpasswd alice. We have not run this exact block on a live server for this post, so test it on a copy first.

The wp-cron.php exception is there for a reason.

WordPress triggers scheduled tasks with a loopback request to wp-cron.php, and spawn_cron() sends no Authorization header, so behind basic auth that request gets a 401 and scheduled posts, update checks and plugin jobs quietly stop.

Exempt the file as above, or set DISABLE_WP_CRON and run wp cron event run --due-now from a real cron job (testing WordPress cron jobs covers both).

Two more costs, both visible in core:

  • Application passwords stop working. When PHP can see basic auth credentials on the front end, WordPress drops the form for creating a new application password from the profile screen, and the authorize screen refuses with "Your website appears to use Basic Authentication, which is not currently compatible with application passwords." Our application passwords post explains why they share the same header.
  • Outside callbacks get a 401. Payment gateway webhooks, Jetpack and anything else that calls your site from outside cannot log in. Exempt their endpoints by path, or use the login wall instead.

Site Health, the plugin and theme file editor, and the automatic updater do forward your basic auth credentials on their own loopback requests, so those keep working while you are logged in through the password prompt.

Is a coming soon page the same as a private site?

No. A coming soon plugin swaps the theme's output for a holding page, but what it does about /wp-json/, feeds and uploads depends on the plugin, and most ranking guides do not check.

If the site is not ready and nothing on it is sensitive, a coming soon page is fine.

If you would be unhappy to see the draft content on someone else's screen, use the login wall plus the REST filter, and test it with the commands below.

For short planned downtime on a live site, maintenance mode is the better fit.

How do I check the site is really private?

Run these from a terminal where you are not logged in. Each should return a redirect, a 401, or a 403, never a 200 with your content in it:

curl -sI https://example.com/ | head -1
curl -sI https://example.com/feed/ | head -1
curl -s  https://example.com/wp-json/wp/v2/posts | head -c 200
curl -sI https://example.com/wp-sitemap.xml | head -1
curl -sI https://example.com/wp-content/uploads/2026/11/some-file.pdf | head -1

Expect the last one to return 200 unless you used server-level auth. That is the honest answer, not a mistake in your setup.

How do I make a WordPress site public again?

Reverse the steps: deactivate the plugin or delete private-site.php from wp-content/mu-plugins, remove the basic auth block, and untick Discourage search engines. Then purge any page cache, or visitors keep getting the login redirect from the cache.

On WordPress.com, privacy is a setting in the site's settings rather than a plugin, and switching it back to Public is the whole job.

Test the lock before you rely on it

Adding a redirect to every request, a REST filter and an .htaccess block to a site people are using is a good way to lock yourself out, or to break cron without noticing for a week. Try it on a copy first.

SandyWP Cloner copies your live site's database, themes, plugins and media into a disposable sandbox, and only reads production while it does. Drop the mu-plugin in over SSH or SFTP, run the curl checks above against the sandbox URL, and check that scheduled events still run with wp cron event list. When the copy behaves, make the same change on the real site, and delete the sandbox.