Secondary Featured Image Function (post_thumbnail)

First thing you need to do is install and activate the Multiple Post Thumbnails plugin. After activating the plugin, you need to add the following code in your theme’s functions.php file. You can add it anywhere in the file as long as you are doing it right. Read our guide on how to paste snippets from the web.

 if (class_exists('MultiPostThumbnails')) {

 new MultiPostThumbnails(array(
   'label' => 'Secondary Image',
   'id' => 'secondary-image',
   'post_type' => 'post'
) );

}

Even though you can add a secondary featured image in your WordPress admin, it will not display on your site until you configure your theme. All you need to do is add the following code inside your post loop where you want to display it. This could be in your single.php (for single posts), archive.php (only for archive pages), etc.

   if (class_exists('MultiPostThumbnails')) : 

      MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image');

   endif;