Ask your WordPress questions! Pay money and get answers fast! (more info)

Help with error fetching video thumbnail WordPress


Hi I am using a theme which auto fetches thumbnails when i embed a video code. Recently it has stopped working and I have been digging to find the source of the error. I noticed that youtube has changed their embed code which now removes the "http:' part of the code.

The auto thumbnail works fine if I manually add "HTTP:" to the embed code

Example that doesnt work:
<iframe width="560" height="315" src="//" frameborder="0" allowfullscreen></iframe>

Example that works:
<iframe width="560" height="315" src="" frameborder="0" allowfullscreen></iframe>

So I am thinking a change needs to be made in the file video-thump.php where the script for fetching the thumbnail is called. Here is a pastebin of that file

How can i append "http:" automatically or change the script to look for a different url. Could the problem be something else?

Thanks for the help

Answers (3)


Hariprasad Vijayan answers:


Change function admin_ajax_thumb_get() with following code,

* Called when we receive the AJAX call to fetch a thumbnail from a given URL
public static function admin_ajax_thumb_get() {
if (isset($_POST['wpzoom_autothumb_embedcode']) && isset($_POST['wpzoom_autothumb_postid'])) {
$url = parent::extract_url_from_embed(trim(stripslashes($_POST['wpzoom_autothumb_embedcode'])));
$postid = intval($_POST['wpzoom_autothumb_postid']);
// Code for adding http:
$first = explode("//", $url);
$url = 'http:'.$url;

if(empty($url) || filter_var($url, FILTER_VALIDATE_URL) === false || $postid < 1) die('ERROR');

$thumb_url = self::fetch_video_thumbnail($url, $postid);
header('Content-type: application/json');
die($thumb_url !== false ? json_encode($thumb_url) : 'ERROR');

Hope this will work. Let me know if you have any trouble.

George Sprouse comments:


Tried this and it didint work. Still get same error

Hariprasad Vijayan comments:

Can you share website credentials in PM. Then i can check it.

Hariprasad Vijayan comments:

where i can see the embed video option in dashboard and the embedded video is public?

George Sprouse comments:

The option is on the right column on the Add a post page. So you will add a new post and you will see it.


phppoet answers:

You need to change a regex that matches with pasted iframe embed code on line 83

try this

wpzValidIframeRegex = /\/\/www\.youtube\.com\/embed\/([\w\-]+)/e;

full code here

if it does not work then try following regex

wpzValidIframeRegex = /\/\/www\.youtube\.com\/embed\/([\w\-]+)/e;

wpzValidIframeRegex = /youtube[.]com/(v|embed)/([^"?]+)/e;

wpzValidIframeRegex = /|embed)/)?[a-zA-Z0-9]+/e;

check this


George Sprouse comments:

Hi phppoet,

Thanks for the lengthy answer unfortunately that didint solve the problem. I tired all the regex you mentioned and in the stackoverflow link and the script doesnt run. When i enter an embed code I don't see anything


Just Me answers:

$url = 'http:'.$url;

should work fine but you should use it in the other function
public static function admin_ajax_thumb_attach()

George Sprouse comments:

Hi Just Me,

Tried this also and it didint work

Just Me comments:

Maybe you are not adding it to the right spot, or it gets filtered out somewhere else.

A less elegant way of doing this would be to add a filter to the content.
Add to your functions.php

add_filter( 'the_content', 'my_the_content_filter', 20 );

function my_the_content_filter( $content ) {

return $content;