I have the URL of my image and I want to display the thumbnail of that image. Is this possible. I check the_post_thumbnail() function but I can't add the URL of the image as an input.

  • Please explain what you are doing in more detail. How is it that you know the URL but can't get the ID?
    – s_ha_dum
    Commented Jan 8, 2016 at 15:50
  • I'm using redux framework. I add an image with that and to diplay that image i use the url. like this: <img src="<?php echo $test_wp['no_image_post_IMG']['url']; ?>"> Commented Jan 8, 2016 at 15:52
  • ok got it: <?php echo $test_wp['no_image_post_IMG']['id']; ?> that get the id (i feel stupid) Commented Jan 8, 2016 at 15:56
  • What is var_dump($test_wp['no_image_post_IMG']);?
    – s_ha_dum
    Commented Jan 8, 2016 at 15:56
  • it is the var of redux Commented Jan 8, 2016 at 15:57

1 Answer 1


Get the image ID from the URL with attachment_url_to_postid():

$image_id   = attachment_url_to_postid( $image_url ); 

Convert the ID to the thumbnail image URL with wp_get_attachment_image_src:

$thumbnail_url = wp_get_attachment_image_src( $image_id, 'thumbnail' );
  • 1
    I was just about to test the function using a featured image URL. Did you try this? At any rate, those "url to ID" functions are resource heavy and best avoided if possible.
    – s_ha_dum
    Commented Jan 8, 2016 at 15:59
  • You should not post bare code. A good answer contains verbal explanation as well. Not my downvote, but I am pretty sure that is the "why" of the vote.
    – s_ha_dum
    Commented Jan 8, 2016 at 16:37
  • Either another user or the system has flagged this as low quality (see flag). Please stop dumping code, to be really honest, this is not the first low quality flag I handle on your of your post. I'm really not after you as you have previously claimed, but I cannot overlook low quality flags in review queue. Add proper explanation to your code to avoid your posts being auto-flagged or being flagged by other users Commented Jan 8, 2016 at 16:41
  • I'm almost certain that single code blocks, like it was originally, are getting always flagged as low quality. So it is better to do the explanation not as code comment, but as regular text. Commented Jan 8, 2016 at 16:59
  • That is an improvement. Links to the Codex page for the relevant functions are always a good thing. caveats are helpful-- "not tested but...", "this might break if..."
    – s_ha_dum
    Commented Jan 8, 2016 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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