Ardrey 情報マガジン

wp json

📅 November 6, 2026📖 Verified Publication

Key Takeaways

  • The wp-json endpoint is the front door to the WordPress REST API, powering block editor features, plugins, and headless integrations.
  • A 404 on /wp-json/ usually points to permalink, rewrite, or server configuration issues rather than a missing plugin.
  • Disabling the REST API entirely can break the block editor, WooCommerce, and many modern plugins.
  • For most sites, the safer approach is targeted restriction, caching, and authentication instead of full shutdown.
  • Always test REST API changes in staging before applying them to production.

What Is wp-json in WordPress?

The wp-json route exposes the WordPress REST API, allowing applications, plugins, and JavaScript interfaces to read and modify site data in a structured format. It is not a physical file; it is a virtual endpoint generated by WordPress rewrite rules. When you visit https://example.com/wp-json/, WordPress responds with JSON containing available routes, namespaces, and endpoints. This architecture powers the block editor, modern plugin dashboards, mobile apps, and headless WordPress builds.

Problem-Solver Q&A: Core Pain Points

Why does /wp-json/ return a 404 error?

A 404 response on /wp-json/ usually means WordPress cannot resolve the rewrite rule that maps the request to the REST API router. Common causes include permalink settings set to Plain, corrupted .htaccess rules, nginx rewrite misconfiguration, aggressive security plugins, or a caching layer serving an old response. Start by visiting Settings, Permalinks, and clicking Save Changes to flush rewrite rules. On Apache, verify that mod_rewrite is enabled and that .htaccess contains the standard WordPress block. On nginx, confirm that try_files routes requests correctly to index.php. If the issue persists, disable security or optimization plugins temporarily and test again.

Is exposing wp-json a security risk?

Exposing wp-json is not automatically dangerous, but it can reveal information such as registered routes, user endpoints, post types, and plugin namespaces. Attackers may use this data to map your site and identify vulnerable components. The risk increases when endpoints allow unauthenticated access to sensitive data or when weak authentication is used. Best practice is to keep the API available for required functionality while restricting sensitive routes, enforcing authentication where needed, and removing unnecessary endpoints. Security through obscurity alone, such as blocking the entire API, often creates more problems than it solves.

How do I disable or restrict the REST API safely?

Fully disabling the REST API is rarely recommended because the block editor and many plugins depend on it. A safer strategy is to restrict access rather than remove it. You can require authentication for specific namespaces, disable user enumeration endpoints, limit application passwords, and use capability checks in custom endpoints. If you must disable public access, use a carefully scoped filter rather than blocking all REST traffic. Always verify that the admin dashboard, WooCommerce, form plugins, and custom integrations still work after changes.

wp-json Management Options Compared

Approach Best For Benefits Risks
Leave REST API enabled Standard WordPress sites Full compatibility with editor and plugins May expose route metadata if not hardened
Restrict sensitive endpoints Most production sites Balances functionality and security Requires testing and ongoing maintenance
Require authentication Headless or API-driven sites Protects private data and actions Can break anonymous front-end features
Disable public REST API Highly locked-down legacy setups Reduces public API surface Can break block editor and plugin features
Cache REST responses High-traffic sites Improves performance and reduces load May serve stale data if cache rules are wrong

Recommended Hardening Checklist

  • Keep WordPress core, plugins, and themes updated.
  • Use strong authentication and limit application passwords.
  • Disable user enumeration endpoints if not needed.
  • Restrict custom endpoints with proper capability checks.
  • Implement rate limiting and a web application firewall.
  • Cache safe GET requests and exclude sensitive routes.
  • Monitor REST API requests in logs for abuse patterns.
  • Test all changes in staging before production deployment.

Frequently Asked Questions

What does wp-json do in WordPress?

wp-json provides the REST API layer that lets external applications and JavaScript interact with WordPress data. It exposes routes for posts, pages, users, media, taxonomies, settings, and plugin-specific functionality. Many core features, including the block editor, rely on this endpoint to save and retrieve content.

Should I block wp-json in robots.txt?

Blocking wp-json in robots.txt is usually unnecessary and can interfere with legitimate crawlers or integrations that rely on API data. If your concern is indexing, use proper HTTP headers or access controls rather than relying solely on robots.txt. Focus on securing endpoints instead of hiding them.

Can caching break wp-json?

Yes. Page caching, object caching, or CDN rules can cache API responses incorrectly, causing stale data, authentication errors, or 404 responses. Configure cache exclusions for dynamic or authenticated REST requests, and ensure cache keys account for authorization headers and query parameters.