Created
November 24, 2021 17:33
-
-
Save wuletawwonte/c250fd114ed22970d6303e8f0dbdb40e to your computer and use it in GitHub Desktop.
A php function to be added to functions.php to enable Wordpress json api give featured image source url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, 'origi> | |
| 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment