Can one set post thumbnail from a function? (5 posts)

  1. Taylor Baybutt
    Posted 4 years ago #

    My client would like to set the post thumbnail from an image url on another website. I understand why this is not built in with the image needing to be uploaded to be resized. However, is there any way to upload the image from a function. If so, I could fulfill their request using custom fields.

    I would need a function something like

    set_post_tumbnail($post_id, $image_url)

    I can't seem to find that this exists. Has anyone jumped this hurdle?

  2. sm_rasmy
    Posted 4 years ago #

    first thing first
    ididt catch you exactly wat you want
    here the way to make a post thumbanil

    here the way to get the thumbanil url

    add this code in the loop

    $image_id = get_post_thumbnail_id();
    $image_url = wp_get_attachment_image_src($image_id);
    $image_url = $image_url[0];
  3. Taylor Baybutt
    Posted 4 years ago #

    That's all well and good but what I want to do is assign an image url (say from an external website) to a post_id as the post thumbnail.

    This would require downloading the image and maybe that is different than uploading an image to the system.

    So the function would probably be something like


    I don't think something like that exists but I can't confirm or deny.

  4. Michael
    Forum Moderator
    Posted 4 years ago #

  5. Taylor Baybutt
    Posted 4 years ago #

    That looks about right. Thanks so much! I will attempt to do it this weekend.

Topic Closed

This topic has been closed to new replies.

About this Topic