Created
July 9, 2015 22:29
-
-
Save petenelson/6e3d8bb43f726e45e97b to your computer and use it in GitHub Desktop.
WordPress REST API: Add featured image link to posts
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
<?php | |
add_filter( 'rest_prepare_post', array( $this, 'add_featured_image_link' ), 10, 3 ); | |
public function add_featured_image_link( $data, $post, $request ) { | |
if ( has_post_thumbnail( $post->ID ) ) { | |
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); | |
$data->add_link( 'featured_image', $featured_image[0], array( 'width' => absint( $featured_image[1] ), 'height' => absint( $featured_image[2] ) ) ); | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment