oEmbed, thumbnails and wordpress

WordPress has wp_oembed_get, which I use to get rich media content with embed.ly. I’ve previously used oEmbed api calls such as this. As you can see it provides thumbnail_url, which I like to use instead of embedding the video. How can I do this with wordpress?

Thanks!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Use the oembed_dataparse filter to modify the resulting HTML output by any given oembed call.

Example:

add_filter('oembed_dataparse','test',10,3);

function test($return, $data, $url) {
    if ($data->provider_name == 'YouTube') {
        return "<img src='{$data->thumbnail_url}'>";
    }
    else return $return;
}

Then putting this in a post:

<p class="responsive-video-wrap clr">

Will give you a picture of Rick Astley instead of a flash video of him. 🙂

Edit: Note that WordPress caches oEmbed results in postmeta. So after making your code, you’ll have to go and Update a post for it to know to go re-get the oEmbed data and have code like this take effect. In case you want to do testing and such.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x