RSS

How to Add Multiple Post Thumbnails / Featured Images in WordPress

02 Sep

Recently one of our readers asked if there was a way to add multiple post thumbnails or featured images in a WordPress post. By default, most WordPress themes come with built-in support for featured images which makes adding post thumbnails really simple. However when working on custom projects, you might need to add a second featured image to a post. In this article we will show you how to add multiple post thumbnails / featured images in WordPress.

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.

1 if (class_exists('MultiPostThumbnails')) {
2
3 new MultiPostThumbnails(array(
4 'label' => 'Secondary Image',
5 'id' => 'secondary-image',
6 'post_type' => 'post'
7  ) );
8
9  }

Once you add that, you can now add a secondary featured image to your post. All you have to do is Edit an existing post or create a new post. You should see a secondary featured image meta box right after the featured image box in WordPress post edit area.

Featured and secondary featured image in post edit area

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.

1 <?php
2
3 if (class_exists('MultiPostThumbnails')) :
4
5 MultiPostThumbnails::the_post_thumbnail(get_post_type(),'secondary-image');
6
7 endif;
8
9  ?>

Once you do that, you are done. Your theme is now ready to display multiple featured images. This is how it looked like when we tested it:

Adding Multiple Post Thumbnails or Featured Images in WordPress

You can repeat this process to add as many featured images as needed. You can also extend the support to other custom post types instead of just posts.

Adding New Thumbnail Sizes

If for some reason you need to change the thumbnail size for the secondary featured image, then you can do so by creating additional image size in WordPress. Don’t forget to regenerate thumbnails or new image sizes. After this you can call the new image size in your multiple post thumbnails code. For example, if you created a new image size with the name secondary-featured-thumbnail you would add this code in your template:

1 <?php
2
3 if (class_exists('MultiPostThumbnails')) :
4
5 MultiPostThumbnails::the_post_thumbnail(get_post_type(),'secondary-image', NULL,  'secondary-featured-thumbnail');
6
7 endif;
8
9 ?>

I hope that this article helped you add multiple featured images to your WordPress themes.

Advertisements
 
10 Comments

Posted by on September 2, 2013 in Wordpress

 

10 responses to “How to Add Multiple Post Thumbnails / Featured Images in WordPress

  1. Pingback: My Homepage
  2. Alejandrina

    September 14, 2013 at 9:16 am

    Thank you for sharing your thoughts. I truly appreciate your efforts and I am waiting for your next write ups thanks once again.

     
  3. Geraldine

    September 14, 2013 at 12:48 pm

    We’re a group of volunteers and opening a brand new scheme in our community. Your web site provided us with helpful information to work on. You’ve done a formidable task and our entire community will likely be thankful to you.

     
  4. Alberta

    September 15, 2013 at 6:45 am

    Hi, after reading this awesome piece of writing i am as well delighted to share my experience here with mates.

     
  5. Pansy

    September 17, 2013 at 9:23 am

    Hey there! Someone in my Facebook group shared this site with us so I came to take a look. I’m definitely enjoying the information. I’m bookmarking and will be tweeting this to my followers! Terrific blog and terrific design and style.

     
  6. Brandi

    September 17, 2013 at 7:34 pm

    What’s Going down i’m new to this, I stumbled upon this I’ve found It positively useful and it has helped me out loads. I hope to contribute & help other users like its aided me. Great job.

     
  7. Romeo

    September 17, 2013 at 11:57 pm

    You actually make it seem really easy together with your presentation however I in finding this matter to be actually something which I think I would never understand. It seems too complicated and extremely huge for me. I am taking a look forward on your next publish, I’ll try to get the grasp of it!

     
  8. Earl

    September 18, 2013 at 2:41 am

    I like reading through a post that will make people think. Also, thanks for allowing for me to comment!

     

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: