Join Morten Rand-Hendriksen for an in-depth discussion in this video Display featured images in the response, part of WordPress REST API (WP-API): First Look.
- View Offline
- Now that you know we can alter the response of the API…by adding new fields, we'll use the same method…to add a new field for the featured image source.…Only this time, we'll get the API…to help us along the way.…The first step is to simply copy…this register API field function,…so I'll copy it and paste it in directly below.…I'll change this to "add featured image"…and I'll change the label to "featured image src".…And I'll change the callback function name…to "image src".…
Then I need to create a new function,…so I'll copy the existing one…and paste it in again, I'll take away this return…and I'll change the name to the callback here, image src.…Alright, so far so good.…Now we are going to use the API…which we already have in the form of this object here…to give us information about the featured image…and then we'll grab the featured image URL.…Now, here it's important to point out…that WordPress really likes give us the featured image…as fully built-out HTML,…but we don't want that fully built-out HTML,…we only want the image source…
With the WP API, developers can access the data on a WordPress site—such as users, posts, and categories—programmatically. The result is an expansion of the already limitless field of possibilities where theme and plugin development is concerned.
This course is a first look at the WP API: what it is, how to get it running, how to interact with it, what it can do for us, and what we can do with it. Join Morten Rand-Hendriksen, your guide and WordPress guru, as he walks through the tools and major features (such as routes and endpoints) of the WP API, as well as a short project that shows how this new API will be used in real-world workflows.
- Installing the WP API
- Exploring common routes
- Examining WP API output
- Building plugins with the WP API
- Crafting WP API URL requests
- Creating AJAX functions with the WP API