Created
November 23, 2018 03:05
-
-
Save imjn/bbfad6528b0e4a55c77b4f3c974bd7de to your computer and use it in GitHub Desktop.
wp get featured image
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
add_action('rest_api_init', 'register_rest_images' ); | |
function register_rest_images(){ | |
register_rest_field( array('post'), | |
'fimg_url', | |
array( | |
'get_callback' => 'get_rest_featured_image', | |
'update_callback' => null, | |
'schema' => null, | |
) | |
); | |
} | |
function get_rest_featured_image( $object, $field_name, $request ) { | |
if( $object['featured_media'] ){ | |
$img = wp_get_attachment_image_src( $object['featured_media'], 'app-thumb' ); | |
return $img[0]; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment