WordPress - how to get uploaded image by filename?

Viewed 2660

How can I get the image that I upload to my media collection - by the image name?

For instance I upload an image called apple.jpg and now I want to get this dynamically without hard-coding its url.

So that I can do something like this:

<img src="<?php echo get_uploaded_image_url_by_name('apple');?>" />

Is it possible?

And better if I can get the info of this image in an array:

array(
   'src' => xxx,
   'alt' => 'xxx',
   'title' => 'xxx'
)

Any ideas?

I have tried with this answer but it does not seem to work:

1 Answers
Related