Make First Post Image as Featured Image | WordPress

Want to show automatic thumbnail in wordpress website. So simple code add in your website and enable to automatic set thumbnail.

How To Do

follow simple steps and paste given code in your functions.php file. Then SAVE now and take e new effect in your active theme –

  • Open cpanel and open pubile_html.
  • Then open wp-content and then open theme.
  • open your active theme’s folder, then open functions.php and paste given code.
function first_image_thumbnail_automatic_thekroyaard($post_id){
$medias = get_attached_media( 'image', $post_id );
if(!has_post_thumbnail($post_id)) {
foreach ($medias as $media) {
set_post_thumbnail($post_id, $media->ID);
break;
}
}
}
add_action('save_post', 'first_image_thumbnail_automatic_thekroyaard');
  • Then SAVE functions.php.

Video