How to get featured image from Wordpress?

In WordPress, when using Featured Image how do I get just the URI to the image? Not the whole bit of HTML?

  • I have read this: http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature I can add an image. I can display an image. But I also have a plugin that I want to access the Feature Image image - sans all the HTML - and email out the URL for the image. How can I get the image's location without all the HTML? Note: There's a bit more to the plugin than just that but for the sake of this discussion it's enough.

  • Answer:

    You can use the follwing to retrieve URL for an attachment thumbnail. $thumb_url = wp_get_attachment_thumb_url( $post_id );

Azizur Rahman at Quora Visit the source

Was this solution helpful to you?

Other answers

a better answer $url = wp_get_attachment_image_src( get_post_thumbnail_id( $post_ID ), 'featured' ); (replace 'featured' with the size of the image you want to have) <img src="<?php  echo $url[0] ?>" width="<?php  echo $url[1] ?>" height="<?php  echo $url[2] ?>"  /> I've included the height and width.  Notice the wp_get_attachment_image_src returns an array which has SRC WIDTH and HEIGHT.  Also notice that with this command you can get any size of image, not just the default thumbnail size. You could of course use it like <div style="background: transparent url(<?php echo $url[0] ?>) no-repeat center center"></div>

Andy Killen

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.