Quick & simple custom REST API routes for WordPress

Рейтинг: 4.9 из 70 оценок

WordPress REST API is a fantastic tool for delivering data either to the front end when you need to use it via JavaScript, or externally if you need to broadcast the data for other services/applications to consume.

Fortunately, it’s also really easy to register custom REST API routes to display exactly what we need.

There are a few options available and if you need a robust system you might consider setting up a custom controller that extends the core WP_REST_Controller class. That’s a great approach if you need a lot of structure and control.

If, however, you need to fire up a route in a hurry, a simple script like the following does a fantastic job. This example will provide a nice output of JSON formatted data at the /wp-json/my-namespace/v1/some/route URI.

Читайте далее

Добавить комментарий