• USD
  • BDT
  • EUR
  • GBP
  • NGN
  • GHS

How to Fix WordPress REST API “404” Error on WP-JSON

Picture of SatisfyHost

SatisfyHost

How to fix WordPress REST API 404 Error on WP-JSON

The WordPress REST API is an essential feature that allows developers to interact with your WordPress site programmatically. It powers many modern WordPress functionalities, including Gutenberg, third-party integrations, and mobile apps. If you’re encountering a “404” error or other issues when accessing domain.com/wp-json, this guide will help you troubleshoot and fix the problem.


What Causes REST API and WP-JSON Errors?

WordPress-REST-API-404-Error-on-WP-JSON

Several factors can lead to issues with the REST API, including:

  1. Broken Permalinks
  2. Faulty Plugins or Themes
  3. Incorrect .htaccess or Server Configuration
  4. Security Plugin Restrictions
  5. PHP Errors or Custom Code

Let’s explore the steps to enable and fix the REST API and wp-json errors.


1. Check and Update Permalinks

The first step is to ensure your permalink settings are correct:

  1. Go to Dashboard > Settings > Permalinks.
  2. Click “Save Changes” without altering the current structure.
how to fix wp rest api 404 error

This action refreshes WordPress’s permalink rules and often resolves 404 errors for REST API endpoints.


2. Verify the .htaccess File

For Apache servers, your .htaccess file must include the correct rewrite rules to enable the REST API. Here is the default .htaccess content:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
  • If the .htaccess file is missing or doesn’t include these rules, create or update it.
  • Ensure the file has the correct permissions (typically 644).

3. Test for Plugin Conflicts

Faulty or misconfigured plugins can interfere with the REST API.

  1. Deactivate all plugins from the Plugins menu.
  2. Check if domain.com/wp-json works.
  3. Reactivate plugins one by one, testing the API after each activation to identify the conflicting plugin.

4. Switch to a Default Theme

Sometimes themes contain custom code that disrupts REST API functionality. To test this:

  1. Switch to a default theme like Twenty Twenty-Three.
  2. Test the REST API endpoint.
  3. If it works, investigate your original theme’s functions.php for code disabling the REST API.

5. Review Security Plugin Settings

Security plugins like iThemes Security or Wordfence might block REST API requests. Check their settings and ensure the REST API is enabled.

  • Look for options like “Disable REST API” or “Restrict REST API access.”
  • Disable such restrictions.

6. Verify Server Configuration

Your server must support WordPress features like pretty permalinks and REST API.

Apache

Ensure mod_rewrite is enabled. Confirm with your hosting provider if unsure.

Nginx

Add the following rule to your Nginx configuration:

location / {
    try_files $uri $uri/ /index.php?$args;
}

Restart the server after updating the configuration.


7. Enable Debugging

Debugging can help identify underlying issues:

  1. Open your wp-config.php file.
  2. Add the following lines:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
  1. Check the debug log at /wp-content/debug.log for REST API-related errors.

8. Reinstall Core Files

If core files are corrupted, reinstall WordPress:

  1. Go to Dashboard > Updates.
  2. Click “Reinstall Now.”

This process replaces core files without affecting your content or settings.


9. Check for Custom Code

Review your theme’s or plugin’s functions.php file for custom code that disables the REST API. For example:

add_filter('rest_authentication_errors', function($result) {
    if (!empty($result)) {
        return $result;
    }
    return new WP_Error('rest_disabled', 'The REST API is disabled.', array('status' => 403));
});

Remove such code to restore REST API functionality.


10. Use the Site Health Tool

WordPress includes a Site Health tool that highlights potential issues:

  1. Go to Dashboard > Tools > Site Health.
  2. Look for errors or recommendations related to the REST API.

Follow the provided guidance to resolve issues.


11. Contact Your Hosting Provider

If the issue persists, contact your hosting provider. Ensure the following:

  • mod_rewrite is enabled (for Apache).
  • Your server meets the minimum requirements for WordPress (PHP 7.4 or higher is recommended).

Conclusion

The WordPress REST API is a powerful tool, and fixing wp-json errors ensures your site functions optimally. By following these steps, you can diagnose and resolve most issues related to the REST API. If you’re still experiencing problems, consider reaching out to WordPress support or your hosting provider for further assistance.

Make the Move to Better Hosting

Switch to high-performance hosting with free migration, no downtime, and a full 14-day refund policy if you’re not satisfied. Try it risk-free and see the difference.