Title: Auto set image
Last modified: August 22, 2016

---

# Auto set image

 *  Resolved [TLegenden](https://wordpress.org/support/users/tlegenden/)
 * (@tlegenden)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/auto-set-image/)
 * Hi, i would like if the plugin took the first image in the post and sat it as
   featured image automatically 🙂
 * I saw this thread but it was closed without answer from the one who suggested
   it, so i thought i could answer those questions because i want that too 😛
    [https://wordpress.org/support/topic/automation-and-various-sizes](https://wordpress.org/support/topic/automation-and-various-sizes)
 * “should it be dynamic or could it be static? That is, imagine the first time 
   you save the post, the first image is foo.jpg. We set that image as the featured
   image. Then, you go edit the post and change the first image of the post from
   foo.jpg to bar.jpg; what featured image should we use, now?”
 * I would prefer if the image did not change when the first in the post is changed,
   but maybe someone else wants it to change, so why not make settings for it so
   people can choose?
 * [https://wordpress.org/plugins/external-featured-image/](https://wordpress.org/plugins/external-featured-image/)

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/auto-set-image/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/auto-set-image/page/2/?output_format=md)

 *  Plugin Author [David Aguilera](https://wordpress.org/support/users/davilera/)
 * (@davilera)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/auto-set-image/#post-5947646)
 * Hi! Thanks for the answer, TLegenden. I’ll work on it as soon as I have some 
   spare time (right now we’re pretty busy with our A/B Testing service for WordPress…)
 *  [MonkimoE](https://wordpress.org/support/users/monkimoe/)
 * (@monkimoe)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947719)
 * Hi.. I’m looking for this feature also.
    This would be great and save our time
   rather than set external featured images manually.
 * I think static image link would be enough.
    But will be great if we update the
   post.. it’s recheck the first image in post then set the first image again.
 * I’m try by put these code in my function.php child theme but doesn’t work:
 *     ```
       function auto_featured_image() {
           global $post, $posts;
   
           if (!has_post_thumbnail($post->ID)) {
               global $post, $posts;
                 $first_img = '';
                 ob_start();
                 ob_end_clean();
                 $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
                 $first_img = $matches [1] [0];
   
                 if(empty($first_img)){ //Defines a default image
                   $first_img = "/images/default.jpg";
                 $attached_image = $first_img;
   
             if ($attached_image) {
                     foreach ($attached_image as $attachment_id => $attachment) {
                          set_post_thumbnail($post->ID, $attachment_id);
                     }
                }
           }
       }
       // Use it temporary to generate all featured images
       add_action('nelioefi_post_meta_key', 'auto_featured_image');
       ```
   
 * I only get “Array” text in admin post external featured image.
 * If this will be a pro feature.. Yes.. of course I will buy for it 😀
    Please 
   make this plugin more powerfull very soon.
 * Thank you for this great plugin.
 *  Plugin Author [David Aguilera](https://wordpress.org/support/users/davilera/)
 * (@davilera)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947720)
 * Hi MonkimoE,
 * I haven’t started working on it yet (the amount of work we have right now is 
   crazy! I hope I’ll have some spare time soon, during this summer :-D).
 * Anyway, your code looks quite good, but the thing is we’re not using attachments
   for inserting the external featured images. Once we’ve officially implemented
   the function, I’ll let you know, guys!
 *  [AnimeHorizon](https://wordpress.org/support/users/animehorizon/)
 * (@animehorizon)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947726)
 * I too would like to cosign on this. This would be the last piece of the puzzle
   that I need. I have multiple editors and don’t want to have to train them (to
   remember) to set the image each time.
 * I know you’re busy; I just want to show that I would be another person to use
   this great feature!
 * Thanks for your time!
 *  [samy234](https://wordpress.org/support/users/samy234/)
 * (@samy234)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947731)
 * Hi if found an easy workaround by chaining this plugin to the existing “WP Autoset
   Featured Image Plus” plugin.
 * You have to manually change the Autoset plugin code to set the Meta information
   required by Nelio external image:
 * Original relevant code block in wp-autoset-featured-image-plus/wpautosetfeaturedimageplus.
   php:
 *     ```
       if ($extImgUrl!="") {
           $thumbId = wpasfiCreateThumb($extImgUrl, $post_id);
           if ($thumbId) {
                 update_post_meta( $post_id, '_thumbnail_id', $thumbId );
            }
       }
       ```
   
 * New code block:
 *     ```
       if ($extImgUrl!="") {
           update_post_meta( $post_id, _nelioefi_url(), $extImgUrl);
       }
       ```
   
 * thats it
 *  Thread Starter [TLegenden](https://wordpress.org/support/users/tlegenden/)
 * (@tlegenden)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947732)
 * Thanks, it works 😀
    I’ll use this method until there is a real auto set for 
   this plugin 🙂
 *  [tunlin007](https://wordpress.org/support/users/tunlin007/)
 * (@tunlin007)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947737)
 * hi samy234 and TLegenden,
 * Would it be possible to provide the plugin that you have put it together?
    I 
   still can’t figure out and not working.
 * Thanks,
    Lin
 *  [discere](https://wordpress.org/support/users/thistlebean/)
 * (@thistlebean)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947738)
 * Hi Samy234,
 * Could you help me trouble shoot why my setup isn’t working?
 *  [samy234](https://wordpress.org/support/users/samy234/)
 * (@samy234)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947739)
 * Hi thistlebean and tunlin007. I will check if i can use the code of the two plugins
   to build a new one that does this. What version of nelio and autoset are you 
   using where it doesn’t work? I didn’t update the plugins since i changed them.
 *  [discere](https://wordpress.org/support/users/thistlebean/)
 * (@thistlebean)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947740)
 * Hello samy234,
 * Thank you for the comment!
 * Versions:
 * Nelio : Version 1.2.0
    WP Autoset : Version 3.0
 *  [PinkishHue](https://wordpress.org/support/users/pinkishhue/)
 * (@pinkishhue)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947744)
 * This is a great workaround, thanks for sharing this!
 * I have edited the code as above and finding that the image is being set in the
   backend of WP but not showing on the front end…not sure why.
 * Will update if I figure it out.
 *  [discere](https://wordpress.org/support/users/thistlebean/)
 * (@thistlebean)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947745)
 * [@pinkishhue](https://wordpress.org/support/users/pinkishhue/),
 * Same issue for me.
 * Apparently what we desire is actually quite a complex problem to solve…
 *  Plugin Author [David Aguilera](https://wordpress.org/support/users/davilera/)
 * (@davilera)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947746)
 * Hey guys!
 * I just uploaded a new version of the plugin that implements the “auto set image”.
   From now one, if a post doesn’t have a regular or external featured image set,
   it’ll use the first image in the content as such. And the best part is: there’s
   no need to use a second plugin along with Nelio External Featured Image for doing
   this!
 * If you don’t want this behavior, you simply need to add the following line in
   your theme’s `functions.php` file:
 *     ```
       add_filter( 'nelioefi_use_first_image', '__return_false' );
       ```
   
 *  [discere](https://wordpress.org/support/users/thistlebean/)
 * (@thistlebean)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947747)
 * David,
 * Thank you. This is awesome!
 *  Plugin Author [David Aguilera](https://wordpress.org/support/users/davilera/)
 * (@davilera)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/auto-set-image/#post-5947748)
 * Glad to help, @thislebean!
 * And, please, [don’t forget to rate the plugin](https://wordpress.org/support/view/plugin-reviews/external-featured-image)!

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/auto-set-image/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/auto-set-image/page/2/?output_format=md)

The topic ‘Auto set image’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/external-featured-image_947a5f.svg)
 * [Nelio External Featured Image (discontinued) - Available in Nelio Content](https://wordpress.org/plugins/external-featured-image/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/external-featured-image/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/external-featured-image/)
 * [Active Topics](https://wordpress.org/support/plugin/external-featured-image/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/external-featured-image/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/external-featured-image/reviews/)

 * 20 replies
 * 9 participants
 * Last reply from: [tunlin007](https://wordpress.org/support/users/tunlin007/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/auto-set-image/page/2/#post-5947753)
 * Status: resolved