WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] How the get the url of post thumbnail image?

[Resolved] How the get the url of post thumbnail image?

Viewing 7 replies - 1 through 7 (of 7 total)
  • keesiemeijer
    Moderator

    @keesiemeijer

    Try it with this (inside the loop):

    $post_thumbnail_id = get_post_thumbnail_id();
    $post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );

    Sisir
    Participant

    @prionkor

    Thanks.. its working.. but i want to get the thumbnail from specific size as i defined the size of the thumbnails:

    add_image_size('blog', 190, 140, true);
    	add_image_size('news', 150, 100, true);
    	add_image_size('page', 650, 270, true);

    I believe this is how I do it…

    <?php $image_id = get_post_thumbnail_id();
    $image_url = wp_get_attachment_image_src($image_id,'large', true);
    echo $image_url[0];  ?>

    where ‘large’ is my thumbnail…..

    Sisir
    Participant

    @prionkor

    Cool.. its working. Another issue that is bugging me last couple of days is that.

    Suppose as my previous code example i have three image sizes. one that i will add in page featured image which i will not use for blog post and news section.

    But when i upload any featured image wordpress will automatically make three new images using those sizes. right? So this can be waste of space in a long run. Is there any way i can prevent this.

    Let me know if anything unclear. Thanks again for your help. Greatly appreciated!

    I don’t know that there is any way to block generation of the image sizes based on context…..

    If storage is a concern, you could just pre make your images, and use custom fields to attach or something.

    But that isn’t all that convenient really…..

    Sisir
    Participant

    @prionkor

    Just checking if there is any way to do that.. like to keep things tight 🙂 but i guess the storage is not really a concern…

    Sisir
    Participant

    @prionkor

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] How the get the url of post thumbnail image?’ is closed to new replies.