wp-rest-api

Register, customize, and debug WordPress REST API endpoints and routes.

14|1|Updated Mar 30, 2026
One-click install
npx skills add https://github.com/wpgaurav/WordPress-skills --skill wp-rest-api-wpgaurav
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: wp-rest-api
Source: https://github.com/wpgaurav/WordPress-skills/tree/main/skills/wordpress/wp-rest-api
Command: npx skills add https://github.com/wpgaurav/WordPress-skills --skill wp-rest-api-wpgaurav

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Streamlines building, extending, and debugging WordPress REST API endpoints by providing a structured, best-practice workflow and guidance.

Core Features & Use Cases

  • Provides guidance on registering routes with register_rest_route and controller-based endpoints.
  • Demonstrates how to validate inputs, secure endpoints with permission_callback, and expose CPTs/taxonomies via show_in_rest.
  • Includes recommendations for response shaping, pagination, and embedding within wp-json responses for robust API design.

Quick Start

To begin, identify the REST endpoint you need, scaffold it using the recommended namespace and route, and test with a client against your WordPress instance.

Frequently Asked Questions about wp-rest-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I register a custom WordPress REST API endpoint?

To register a custom WordPress REST API endpoint, use register_rest_route with a unique namespace, define route arguments, implement input validation, and attach a permission_callback to secure access. This ensures safe route registration and properly formatted responses.

Why does my WordPress REST API return a 401 or 403 error?

WordPress REST API 401 or 403 errors occur when authentication fails or permission callbacks restrict access. Troubleshoot by verifying authentication credentials and ensuring your route's permission_callback explicitly grants the current user access.

How do I expose custom post types via the WordPress REST API?

To expose custom post types via the WordPress REST API, set show_in_rest to true when registering your post type or taxonomy. This automatically adds your CPTs to the wp-json responses for robust API design.

What is the best way to structure WordPress REST API responses?

The best way to structure WordPress REST API responses is by using controller-based endpoints to shape data, implementing pagination for large datasets, and utilizing embedding within wp-json responses for robust and efficient API design.

How do I add argument validation to WordPress REST API routes?

Add argument validation to WordPress REST API routes by defining validation rules within the register_rest_route arguments array. This ensures incoming data meets your endpoint requirements before processing requests.

Why does my custom WordPress REST API route return a 404?

A custom WordPress REST API route returns a 404 when the namespace or route path is incorrect or the rest_api_init hook is missing. Verify your unique namespace and ensure registration occurs within the proper hook.