Enhances the featured image data returned on the post object by the REST API to include urls for all available sizes and other useful image data.
FAQ
How does it work?
The WP REST API includes a filter on the response data it returns, and this plugin uses that filter to add a new field better_featured_image
with the extra data for the featured image.
When does the plugin load?
The plugin loads on init
at priority 12, in order to come after any custom post types have been registered.
Why doesn’t the plugin replace the default `featured_media` field?
The featured_media
field is a core field, and other applications might expect it to always be an integer value. To avoid any issues, this plugin includes the extra data under the better_featured_image
field name.
Why is the core field called `featured_media` but the plugin field is `better_featured_image`?
Prior to V2 Beta 11 of the REST API the core field was called featured_image
. As of Beta 11 this field was changed to featured_media
, with the idea that at some point in the future there may be additional media items included on this field beyond the featured image. Version 1.1.1 of this plugin is compatible with both Beta 11 and all previous versions of V2.
ChangeLog
1.2.1
- Add fix for bug caused by conflicts with plugins that manipulate image metadata
1.2.0
- Fix translation files present but not loading
- Add note to the readme explaining that
?_embed
should be tried before using this plugin
- Fix compat with older betas
- Add missing PHPDoc statements
- Tested with v2 beta 12
1.1.1
- Compatibility with v2 beta 11 of the REST API (now the core field is called featured_media; this plugin’s field is still better_featured_image). Props: filose
1.1.0
- Add a better_rest_api_featured_image filter for adding custom data to the response. Props: avishayil
1.0.2
- Change register_api_field to register_rest_field for compatibility with the REST API v2 beta 9. Props: Soean
1.0.1
- Switch to returning null instead of 0 when no featured image is present
1.0.0