This is the simplest solution I was able to find that actually worked. Add the following code to your functions.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php function post_featured_image_json( $data, $post, $context ) { $featured_image_id = $data->data['featured_media']; // get featured image id $featured_image_url = wp_get_attachment_image_src( $featured_image_id, 'original' ); // get url of the original size if( $featured_image_url ) { $data->data['featured_image_url'] = $featured_image_url[0]; } return $data; } add_filter( 'rest_prepare_post', 'post_featured_image_json', 10, 3 ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.