How to set youtube thumbnail from YouTube embed code as display image in Wordpress?

How to set the external URL of a youtube thumbnail (without uploading it on my website) a YouTube video with an iframe code to embed a youtube video?

Is it possible to create a function that pulls out the external URL of a YouTube thumbnail and set it as an image with:

<iframe width="420" height="315" src="www.youtube.com/embed/gTp4sZtjHS" frameborder="0" allowfullscreen></iframe> 

Do not ask about OEmbed or similar things, I think the question is clear.

+4
source share
1 answer

The format for pulling a large image from a YouTube video is http://img.youtube.com/vi/A4a0xZMMlqE/0.jpg just replace "A4a0xZMMlqE" with the video ID.

I think the easiest way to set this up is to forget about using it as the displayed image, but just dynamically drawing it into the template.

So, in your post, make a custom field that will contain the YouTube video identifier, and in the template do something like:

 <img src="http://img.youtube.com/vi/<?php echo get_post_meta($post->ID,'youtubeId');?>/0.jpg"/> 

Does your problem solve?

Otherwise, if you look at the really made image, you probably look at the development of a custom plugin: http://net.tutsplus.com/tutorials/wordpress/creating-a-custom-wordpress-plugin-from-scratch/ which are likely to use wp_insert_attachment

I also found media_sideload_image that I did not know about. It will pull the image from the URL (i.e. YouTube Link) and attach it to the message.

+29
source

Source: https://habr.com/ru/post/1492435/


All Articles