I have changed my question. I was wrong. Check it out I'd say.

Is this possible to make a thumbnail if a link contains a .jpg (or .png) extension?

I want to make it a thumbnail automatically if there is a link like http://externalsiteorso.com/blablabla.jpg --> make this a thumbnail.

If it's possible, how can I do this and solve the problem?

I have found this, but it's not for Wordpress, I guess.

$extension = pathinfo($filename, PATHINFO_EXTENSION);

// Read source image
if ($extension == ('jpg' || 'jpeg')) {
    $source_image = imagecreatefromjpeg($filename); 
    return '1';
} else if ($extension == 'png') {
    $source_image = imagecreatefrompng($filename);
    return '2';
} else {
    return 'error';
  • how do you call this function in your template?
    – Michael
    Aug 3, 2013 at 18:19
  • Like this <?php get_first_image(); ?> Aug 3, 2013 at 18:36
  • 2
    That function returns an image URL when I test it but that alone is not going to create a thumbnail.
    – s_ha_dum
    Aug 3, 2013 at 18:36
  • Well, can someone help me making it a thumbnail? Where do I start, what should I do? Aug 3, 2013 at 19:21
  • Whad to you need exactly, can you explain more?
    – Greeso
    Aug 3, 2013 at 20:40

1 Answer 1


1) Check out:


2) I found that WP function to be somewhat limited to I wrote my own wrapper class/method. If you want to do the same you're going to need PHP's copy() function


as well as WP's wp_insert_attachment()


Unfortunately, I haven't pushed my code to GitHub just yet, so for now you'll have to put something together yourself.

  • I am not that good in coding, but will look at it at least. Thanks. Aug 6, 2013 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.