WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How the get the url of post thumbnail image? (8 posts)

  1. prionkor
    Member
    Posted 3 years ago #

    Hi, a small question. I could not find the answer in documentation. Maybe i am looking in wrong place. When we echo the post thumbnail it comes with the img tag. But what should i do if i want only the image source url?

    Let me know if anything not clear. Thanks!

    pages i looked at:
    http://codex.wordpress.org/Function_Reference/the_post_thumbnail
    http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    Try it with this (inside the loop):

    $post_thumbnail_id = get_post_thumbnail_id();
    $post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
  3. prionkor
    Member
    Posted 3 years ago #

    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);
  4. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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.....

  5. prionkor
    Member
    Posted 3 years ago #

    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!

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    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.....

  7. prionkor
    Member
    Posted 3 years ago #

    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...

  8. prionkor
    Member
    Posted 3 years ago #


Topic Closed

This topic has been closed to new replies.

About this Topic