Do you see this error when trying to access WP json data via Rest API? Example: https://yourwebsite.com/wp-json/wp/v2/posts
{
"code": "rest_not_logged_in",
"message": "You are not currently logged in.",
"data": {
"status": 401
}
}
❓ What it Means:
This means that public (unauthenticated) access to the REST API for posts is currently restricted on your WordPress site.
Normally, the endpoint:
https://your-site.com/wp-json/wp/v2/posts
should return a list of published blog posts even if the user is not logged in. But in your case, the site has some restriction that requires users to be logged in to use the REST API.
🔒 Why This Happens:
This usually happens because of one of the following:
-
Security Plugin Restriction (e.g., Wordfence, iThemes Security)
-
Code Snippet or Custom Plugin that blocks REST access
-
Theme functions.php modification that disables REST API for non-logged-in users
✅ How to Fix It (Allow Public Access):
Option 1: Check for Custom Code or Plugins
Look for code like this in your functions.php or a custom plugin:
add_filter('rest_authentication_errors', function($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;
});
🛠 If you find this code, remove or comment it out.
Option 2: Use a Plugin to Manage REST API Access
Install a plugin like:
-
“Disable REST API”
-
“WP REST API Controller”
These plugins give you control over which endpoints are public.
Option 3: Temporarily Allow REST Access for Posts
If you want to allow just the /wp/v2/posts endpoint for public users, add this to your theme’s functions.php:
add_filter('rest_authentication_errors', function($result) {
if (!empty($result)) {
return $result;
}
// Allow public access to the posts endpoint
if (strpos($_SERVER['REQUEST_URI'], '/wp-json/wp/v2/posts') !== false) {
return true;
}
if (!is_user_logged_in()) {
return new WP_Error('rest_not_logged_in', 'You are not currently logged in.', array('status' => 401));
}
return $result;
});