How to Disable WordPress REST API Without a Plugin

The WordPress REST API is a built in interface that lets other software read and change your site content over HTTP. It powers the block editor, the WordPress mobile app, and many plugins that need to talk to your site. It is also publicly reachable by default, and anyone on the internet can open an address such as yoursite.com/wp-json/wp/v2/users and see a list of your users, including their usernames. That is a real information leak, and it is the main reason site owners ask how to disable the WordPress REST API without a plugin.
The honest answer is that a full disable is usually the wrong move. The block editor itself uses the REST API to save posts, so turning it off completely breaks editing for everyone, including you. The right approach is to restrict the API instead of removing it: let logged in users keep using it, and block anonymous visitors from the parts that leak information. This guide shows how to do exactly that with a small code snippet, plus a targeted fix for the users endpoint and a server level alternative, and it explains how to test each change so you know it worked.
What Is the WordPress REST API?
The REST API is a set of web addresses under /wp-json/ that return your site content as structured data instead of as a web page. A request to /wp-json/wp/v2/posts returns your posts, /wp-json/wp/v2/pages returns your pages, and /wp-json/wp/v2/users returns your users. Software reads that data, changes it, or displays it somewhere else. The block editor uses these addresses every time you save a post, upload media, or update a setting. The WordPress mobile app uses them to show your site on your phone. Many plugins use them too, for example form plugins that submit entries and membership plugins that check a user status. The official REST API handbook documents every endpoint and explains how authentication works.
The API has been part of WordPress core since version 4.7, and it is enabled on every WordPress site unless something turns it off. You cannot see it in the normal settings pages, because there is no on or off switch in the dashboard. That invisibility is part of the problem: most site owners do not know it exists until someone shows them the user list it exposes. The API is not a bug or a hack. It is a designed feature, and the user endpoint was made public so that author pages and similar features could work. The problem is that the same public access also hands attackers a list of valid usernames, which is the first half of a login attack.
Why Is the REST API a Security Concern?
The main leak is the users endpoint. Open /wp-json/wp/v2/users in a browser while logged out, and on many sites you will see a JSON list of users with their IDs, names, and slugs. The slug is usually the username, which means an attacker now knows the exact username to target with password guessing. Usernames are meant to be half of a secret, and the REST API gives that half away for free.
The posts endpoint is less of a concern, because your posts are already public on the site itself. The same applies to pages, categories, and tags. The real risk is concentrated in the users endpoint and in any endpoint a plugin adds that exposes private data. There have also been past vulnerabilities in the REST API itself, including a well known content injection issue in early 2017, which is why keeping WordPress updated matters as much as any restriction you add. Restricting the API does not replace updates, strong passwords, and a backup routine. Our web hosting guide explains how a good host adds a firewall layer on top of these settings, and our guide to back up your WordPress database without a plugin is the safety net you need before changing anything security related.
Why Should You Not Fully Disable the REST API?
It is tempting to switch the whole API off and be done with it, but that breaks things you use every day. The block editor saves posts through the REST API, so a full disable means the editor shows an error when you try to save or publish, and autosave stops working. The WordPress mobile app stops working too, because it has no other way to reach your site. Plugins that rely on the API break in confusing ways: forms may fail to submit, live search may stop returning results, and eCommerce checkouts can misbehave. You would trade a username leak for a broken editing experience.
That is why the recommended approach is restriction, not removal. Logged in users with the right permissions keep full API access, so the editor and your plugins keep working. Logged out visitors get a clear error instead of your data. This is the same model WordPress itself uses for the admin area: public visitors see the public site, and only logged in users can change things. Restricting the API applies that same logic to the /wp-json/ addresses.
Method 1: How Do You Restrict the REST API to Logged In Users?
This is the recommended method for most sites. A short snippet hooks into the authentication check that WordPress runs before every REST API request. If the visitor is not logged in, the snippet returns an error and WordPress refuses the request. If the visitor is logged in, the request proceeds normally. Add the snippet with the Code Snippets plugin or in your child theme functions.php file, and set it to run on the front end only. The same snippet workflow is used in our guide to disable XML-RPC in WordPress, which closes another public interface worth reviewing at the same time.
add_filter( 'rest_authentication_errors', 'vutg_restrict_api_to_logged_in_users' );
function vutg_restrict_api_to_logged_in_users( $result ) {
if ( ! empty( $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;
}
After saving the snippet, test it in a private browser window while logged out. Open yoursite.com/wp-json/ and you should see a JSON error with the code rest_not_logged_in and a 401 status, instead of the normal list of routes. Then log in and open the same address, and you should see the normal route list again. Open the block editor and save a test post to confirm editing still works.
Method 2: How Do You Block Only the Users Endpoint?
If a full restriction breaks something on your site, block just the endpoint that leaks usernames. The snippet below removes the users routes from the API for logged out visitors while leaving every other endpoint working exactly as before. It hooks into the endpoint list and unsets the user routes when no user is logged in, so the editor, forms, and plugins keep working, but the username list disappears.
add_filter( 'rest_endpoints', 'vutg_block_users_endpoint_for_visitors' );
function vutg_block_users_endpoint_for_visitors( $endpoints ) {
if ( is_user_logged_in() ) {
return $endpoints;
}
foreach ( $endpoints as $route => $handlers ) {
if ( 0 === strpos( $route, '/wp/v2/users' ) ) {
unset( $endpoints[$route] );
}
}
return $endpoints;
}
Test this method the same way. While logged out, open yoursite.com/wp-json/wp/v2/users and you should see a 404 error saying no route was found. While logged in as an administrator, the same address should show the user list again. Also check your author archive pages, because those still reveal usernames in their URLs, and this snippet does not change them. If author archives are a concern, consider hiding them or changing the author slug, but that is a separate job. The targeted method is the safest choice for stores and membership sites, because it changes the least. If your store uses WooCommerce, test the checkout and the cart after adding the snippet, since our guide to disable guest checkout in WooCommerce shows how checkout behaviour depends on user sessions.
Method 3: Can You Block the REST API With .htaccess?
A server level block in .htaccess can stop requests to /wp-json/ before WordPress even loads, which is faster than a PHP filter. This method is powerful, but it comes with a clear warning: it blocks the API for logged in users too, including the block editor, unless you add an exception for your own IP address or for requests that carry a login cookie. A blanket .htaccess block has the same breakage problem as a full PHP disable, so use it only on sites that never use the block editor and have no plugin that needs the API.
Because .htaccess mistakes can take a site down with a 500 error, always download a copy of the file before editing it, and test the site immediately after saving. The .htaccess method also does nothing if your site runs on Nginx, which does not read .htaccess files at all. For most site owners, the PHP methods above are the right choice, and the server level block is only for advanced setups.
How Do You Test That the REST API Is Restricted?
Testing takes two minutes and you should not skip it. Open a private browser window, which guarantees you are logged out, and visit yoursite.com/wp-json/ first. With Method 1 active, you should see the rest_not_logged_in error. With Method 2 active, you should see the normal route list, because only the users endpoint is blocked. Then visit yoursite.com/wp-json/wp/v2/users in the same private window. With either method active, you should see an error instead of the user list. Finally, log in, open the block editor, and save a post. If the save works, the editor is unaffected. If you manage users and roles on the site, our guide to WordPress user roles explained helps you decide which roles should keep API access.
What Do You Do If a Plugin Needs the REST API?
First, identify the plugin and the endpoint it needs. The usual suspects are form plugins, live search, page builders with dynamic content, and headless or mobile app connections. Test the plugin feature while logged out, because that is when the restriction applies. If it fails, switch from Method 1 to Method 2, which leaves the whole API open except for the users endpoint, and that fixes most plugin conflicts. You can also add a narrow exception to the Method 1 snippet for the specific route the plugin needs, or check whether the plugin offers its own authentication, such as an application password, which lets it log in as a user and use the API legitimately. Never solve a plugin conflict by removing the restriction entirely without understanding what data you are exposing again. A slow dashboard can also be caused by plugins polling the API too often, and our guide to fix a slow WordPress admin dashboard shows how to find those.
Frequently Asked Questions
Will disabling the REST API break the block editor?
A full disable will break it, because the editor saves posts through the API. Restricting the API to logged in users does not break it, because you are logged in while editing. Always test saving a post after adding any restriction snippet.
Does blocking the users endpoint hide my username completely?
No. The users endpoint is one leak, but author archive pages and post bylines can still reveal usernames. Blocking the endpoint removes the easiest bulk lookup, and you should review author archives separately if hiding usernames is a priority.
Can I disable the REST API with a setting in the dashboard?
No. WordPress has no built in setting to disable or restrict the REST API. You need a code snippet like the ones in this guide, or a security plugin that offers the option. The code approach keeps your site lighter than adding a plugin for one setting.
Is the REST API needed for the WordPress mobile app?
Yes. The mobile app communicates with your site through the REST API, so a full disable stops the app from working. The logged in user restriction in Method 1 keeps the app working, because the app logs in with your account before it makes API requests.
Last updated: December 2026.



