WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Plugins» How to Add Multiple Post Thumbnails / Featured Images in WordPress

How to Add Multiple Post Thumbnails / Featured Images in WordPress

Last updated on May 21st, 2013 by Editorial Staff
86 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
How to Add Multiple Post Thumbnails / Featured Images in WordPress

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. 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'
 ) );

 }

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.

<?php 

if (class_exists('MultiPostThumbnails')) : 

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

endif;

 ?>

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:

<?php 

if (class_exists('MultiPostThumbnails')) : 

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

endif;

?>

We hope that this article helped you add multiple featured images to your WordPress themes. What are some use cases that you can think of for this plugin? When can you see yourself adding multiple post thumbnails in WordPress? Let us know by leaving a comment below.

86 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • How to Properly Move Your Blog from WordPress.com to WordPress.org

  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

57 Comments

Leave a Reply
  1. Thodoros Athineos says:
    Jun 10, 2020 at 1:33 am

    This is very handy for many purposes that special images might be needed (eg mobile-image).

    BUT
    Is it possible for your future plans, to provide the ability of an array of images, instead of single?

    For example, the developer might need to add an album-images instance, in order that user can select multiple images to be provided to an album.

    Reply
    • WPBeginner Support says:
      Jun 10, 2020 at 8:57 am

      We will look into possibly adding that in the future but you may need to look into a plugin for that level of customization.

      Reply
  2. Robin Parker says:
    Apr 19, 2019 at 3:44 pm

    hi, everything works down to this paragraph.

    “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.”

    Can you explain a little more about where to place this part of the code within the theme? Thx!

    Reply
    • WPBeginner Support says:
      Apr 22, 2019 at 1:16 pm

      That would depend on your specific theme, normally it should have the code to display your content and you would place the code in that area, for understanding the loop you would want to take a look at the page: https://www.wpbeginner.com/glossary/loop/
      For where to place the code for how you’re wanting it, you would want to reach out to your theme’s support.

      Reply
  3. Parvez says:
    Mar 20, 2019 at 12:07 am

    I want to add two images; one as a thumbnail (in search engine, archives, homepage or any other place it showed) and another one as featured image (Reader will see this image only at the time of reading content).

    Is there any solution for my problem?

    Reply
    • WPBeginner Support says:
      Mar 20, 2019 at 10:43 am

      You would want to reach out to the support for the theme you are using for that type of customization.

      Reply
  4. Lisa says:
    Nov 24, 2017 at 3:42 pm

    Hi. Could you possibly update older articles? This one uses a plugin that hasn’t been updated in over 2 years.

    Just wondering.

    Reply
    • Kashif Riaz says:
      Jun 21, 2018 at 2:04 pm

      Hi, Please tell me how to access the second thumbnail. For example we can access the default featured image by “the_post_thumbnail()”.

      Reply
  5. Otaku Desu says:
    Oct 7, 2017 at 12:22 am

    please… can someone help me
    i just want take the url image
    how do that?

    Reply
  6. Kristina says:
    Apr 18, 2017 at 2:11 pm

    Why isn’t the “Multiple Post Thumbnails” updated? It said that it was last updated 2 years ago. It needs to be updated because some people cannot use plugins that wasn’t updated since 2-3 years ago…

    Reply
  7. Leslie says:
    Mar 3, 2017 at 3:41 pm

    I hope you can help me. Can you tell me if this plugin can do what I need?

    I need to be able to add a second featured image to a post (or custom post type) that is in more than one category. On the archive page for one of the categories, I need for the second featured image thumbnail to show, and everywhere else on the site I need for the first featured image thumbnail to show.

    Thanks for whatever you can tell me!

    Reply
    • WPBeginner Support says:
      Mar 3, 2017 at 4:47 pm

      Hey Leslie,

      We are not sure this plugin can do that on its own. You will probably need to edit your theme files to achieve this.

      Reply
  8. Nick W says:
    Feb 20, 2017 at 1:23 pm

    I use genesis and i cannot figure out where to paste this snippet so the 2nd featured image shows only as the thumbnail on the home and category pages. Please help.

    Reply
  9. Lance says:
    Nov 21, 2016 at 10:30 pm

    Great Plugin! Could it be possible to make it so when there is a secondary image set, that only the secondary image shows?

    Reply
  10. yasir kham says:
    Sep 9, 2016 at 6:03 am

    it really help full for me Thank’s

    Reply
  11. Brian says:
    May 25, 2016 at 12:58 am

    Can you add it to just one page in the admin area. Like if i wanted to just add it to the front-page.php file in the admin area so if you go to edit another page it is not on it in the admin area?

    Reply
  12. birjit says:
    Apr 29, 2016 at 12:37 am

    how to get secoundry featured image id

    Reply
  13. Neil desucatan says:
    Apr 14, 2016 at 10:35 am

    Hi i’m new with wordpress and i hope you can help me :) with this

    i need to use this to my sidebar.php but now showing the secondary image

    Reply
  14. Anas Iqbal says:
    Mar 3, 2016 at 2:19 am

    Hi, I am using this plugin with NewsPaper WordPress theme but everytime it display the latest secondary image added in all post.

    Like I display 6 posts in sidebar, and secondary image was added in just first 2 posts, but the same image will display in all 6 posts.

    Please tell me how can I use this with NewsPaper WordPress theme.

    Reply
  15. Joseph says:
    Feb 14, 2016 at 11:44 pm

    this isn’t working for me, 2nd featured image is not showing in page editor.

    Reply
  16. Barrett Hemmings says:
    Dec 8, 2015 at 12:02 pm

    Is there a way to use this method to assign a secondary featured image based on a category that is chosen? I am building a site for a reclaimed wood company that does all kinds of projects and some of the project photos have multiple categories within them. For instance, one project we did has items throughout the house that we did, and we included the category “Shelves” to a posting that the featured image doesn’t show any shelves. That project will be displayed within a page of shelves and have the featured image of a counter top. Is there any way to make it display one of the photos of the shelves when it is displayed in this category?

    Reply
    • Ankita says:
      Apr 12, 2016 at 5:23 am

      there is always an id for any post type so in your case if it is “shelves” then ‘post_type’ => ‘shelves’ will be in your code.

      Reply
  17. tareq says:
    Dec 1, 2015 at 1:09 am

    It’s really working on post. bt i wanna set it on custom post. How can i add multiple feature image in custom post?

    Reply
  18. Patrick Buntsma says:
    Nov 29, 2015 at 8:48 am

    It might be very easy, but I cannot seem to get it right…
    How do I get it to show up in all my post types? The ‘post_type’ => ‘post’ only makes it available in WP Posts. I need it in ‘page’ and ‘event’ as well.

    Please advice.

    Reply
  19. Abdul wahab says:
    Apr 1, 2015 at 10:59 am

    The 2nd feature image is not showing,how i can get the image ID?

    Reply
  20. David says:
    Mar 9, 2015 at 1:46 pm

    How can i get the ID of the extra Thumbnail?

    Reply
  21. Anas Naqvi says:
    Oct 21, 2014 at 5:10 pm

    for multiple feature images copy this code in your functions,php

    if (class_exists(‘MultiPostThumbnails’)) {

    for($i=2; $i ‘Secondary Image-‘.$i,

    ‘id’ => ‘secondary-image-‘.$i,

    ‘post_type’ => ‘page’

    ));

    }

    }

    In order to display your featured image paste this code in your loop of your single.php/page.php where you want to display the images.

    if (class_exists(‘MultiPostThumbnails’)) :

    for($i=2; $i<=5; $i++)

    {

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

    }

    endif;

    Reply
  22. Rajith Gunawardena says:
    Oct 21, 2014 at 8:55 am

    this is a very useful tutorial.. So the admins doesn`t need to go to widgets as all items could be added at once ( if the items are unique to that post ./ page ) .. Does anyone of you guys know how we could have a similar one for featured text and extra text areas within the post ?

    Reply
  23. Rajith Gunawardena says:
    Sep 22, 2014 at 1:45 am

    this is very useful and i manage to get it to work without any issue. do you know how we could have a similer things with FEATURED TEXT and MULTiPLE FEATURED TEXT ?

    Reply
  24. amitmojumder says:
    Jun 18, 2014 at 9:25 pm

    What if somebody wants to show more than 2 featured images? say 10-12?

    Reply
    • KyawNaing Tun says:
      Sep 23, 2014 at 1:22 am

      I solved it like this :)

      // in function.php

      if (class_exists(‘MultiPostThumbnails’)) {

      new MultiPostThumbnails(array(

      ‘label’ => ‘Secondary Image’,

      ‘id’ => ‘secondary-image’,

      ‘post_type’ => ‘product’

      ) );

      new MultiPostThumbnails(array(

      ‘label’ => ‘Third Image’,

      ‘id’ => ‘third-image’,

      ‘post_type’ => ‘product’

      ) );

      }

      // in template

      if (class_exists(‘MultiPostThumbnails’)) :

      MultiPostThumbnails::the_post_thumbnail(get_post_type(), ‘secondary-image’);

      endif;

      if (class_exists(‘MultiPostThumbnails’)) :

      MultiPostThumbnails::the_post_thumbnail(get_post_type(), ‘third-image’);

      endif;

      Reply
  25. MatsDagerlind says:
    May 2, 2014 at 6:12 am

    I solved it like this (based on code provided in this article, its comments and other sources):

    MultiPostThumbnails::the_post_thumbnail(get_post_type(), ‘secondary-image’, NULL, ‘medium’);
    $mptId = MultiPostThumbnails::get_post_thumbnail_id(‘post’, ‘secondary-image’, $post->ID);
    $p = get_post($mptId);
    echo “”;
    echo apply_filters(‘the_excerpt’,$p->post_excerpt);
    echo “”;

    Reply
  26. MatsDagerlind says:
    Apr 28, 2014 at 11:06 pm

    I know you explained in another topic (https://www.wpbeginner.com/wp-tutorials/how-to-display-wordpress-post-thumbnails-with-captions/) how to get and show the caption (excerpt) for a thumbnail, but I don’t quite get how to do this in the context above. If someone could show what to add to the code sample to show the caption beneath the thumbnail, I would be very grateful.

    Reply
  27. Vinnie James says:
    Apr 24, 2014 at 8:44 pm

    Is it possible to just return the image url without the tag when calling it up within the template file? Something similar to:

    //Get the Thumbnail URL
    $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array(320,240), false, ” );
    echo $src[0];

    EDIT: Yes, there is. Use this —
    $custom = MultiPostThumbnails::get_post_thumbnail_id(‘post’, ‘secondary-image’, $post->ID); $custom=wp_get_attachment_image_src($custom,’post-secondary-image-thumbnail’); echo $custom[0];

    Reply
    • KyawNaing Tun says:
      Sep 23, 2014 at 4:16 am

      Thanks @Vinnie James

      Reply
  28. Masood says:
    Mar 24, 2014 at 2:57 am

    Thank you for this article its very help full for bigner like me

    Reply
  29. gunadi says:
    Mar 13, 2014 at 2:49 am

    hi, this perfect plugin.
    but, can i create slider with this plugin..?

    thank’s :)

    Reply
  30. Mehdi says:
    Mar 5, 2014 at 6:17 am

    Hi, Thank you for your work :)

    Using this plugin, can I add more than 1 additional Thumbnail image ??

    Thank you.

    Reply
    • WPBeginner Support says:
      Mar 8, 2014 at 6:30 pm

      Yes you can.

      Reply
      • Mehdi says:
        Mar 13, 2014 at 1:23 pm

        Awesome! But it looks that from the back-office I can only add One secondary image. How can I achieve that ?
        Thank you.

        Reply
        • Mehdi says:
          Mar 13, 2014 at 1:41 pm

          Sorry, this is how we can do it :

          // To be Added in functions.php
          // Multi-Thumbnails code
          if (class_exists(‘MultiPostThumbnails’)) {
          for($i = 1; $i ‘Gallery Image’.$i,
          ‘id’ => ‘image-‘.$i,
          ‘post_type’ => ‘post’
          ));
          }
          }

          Thank you.

  31. Steve says:
    Jan 29, 2014 at 3:27 am

    Great article!

    Just what I’ve been looking for.

    But how I could make it work with a custom post type?

    Reply
  32. abid says:
    Jan 16, 2014 at 8:35 am

    got it, just copy and past this function how many time you want feature images, and change id and label…:)

    Reply
  33. abid says:
    Jan 16, 2014 at 8:30 am

    how to add upto 5 or 6 features images…?

    Reply
  34. abdul says:
    Dec 31, 2013 at 4:33 am

    What is different between default image and featured image in wordpress./////////////??????????

    Reply
    • WPBeginner Support says:
      Dec 31, 2013 at 5:04 pm

      The featured image is an image that you can attach to a post using the featured image box in the post edit area. If you want, you can set a default fallback image for your featured images. This default featured image will appear when there is no featured image set for a post.

      Reply
  35. Gunaseelan says:
    Dec 9, 2013 at 1:56 am

    I have created a plugin for displaying Page Title, Featured Image and the content.

    Instead of displaying featured image, I need to display the secondary image that is uploaded via plugin.

    How to accomplish this? I will share a small part of my plugin. Please go through it.

    function widget($args, $instance) {
    extract( $args );
    $title = apply_filters(‘widget_title’, $instance[‘title’]);
    $page_id = $instance[‘page_id’];
    $featured_image = get_the_post_thumbnail($page_id);
    $image = $instance[$featured_image];
    echo $featured_image;

    ?>

    post_content;
    $content = strip_shortcodes($content);
    $content = apply_filters(‘the_content’, $content);
    echo $this->break_text($content, $page_id);
    ?>

    <!––>
    <!––>

    <?php
    }

    Reply
    • WPBeginner Support says:
      Dec 9, 2013 at 3:17 pm

      Please use support tab on plugin’s page at WordPress.org also check out the FAQs there.

      Reply
  36. Eoghan says:
    Nov 21, 2013 at 11:46 am

    I cannot get the resize part to work for me.

    I add image size in functions.php:
    add_image_size(‘small-featured-image-size’, 250, 150);

    I add my image:
    if (class_exists(‘MultiPostThumbnails’)) {
    new MultiPostThumbnails(
    array(
    ‘label’ => ‘Small Featured Image’,
    ‘id’ => ‘smaller-featured-image’,
    ‘post_type’ => ‘product’
    )
    );
    }

    And then:
    if( class_exists(‘MultiPostThumbnails’) ) {
    MultiPostThumbnails::the_post_thumbnail(‘product’, ‘smaller-featured-image’, NULL, ‘small-featured-image-size’);
    }

    The image keeps coming out on the page as its original size. Can anyone help me?

    Reply
    • WPBeginner Support says:
      Nov 23, 2013 at 11:15 am

      Eoghan first you need to create ‘smaller-featured-image’ image size. Check out how to create additional image sizes in WordPress and then how to regenerate thumbnails.

      Reply
    • wgoodman says:
      Jan 1, 2014 at 11:40 pm

      I tried to get it to work by copying the code on this page and pasting it in my functions.php. It did not work until I realized that I was pasting smart apostrophes. Once I changed them it worked great. I think this is what happen to EOGHAN. Thank you for making this webpage. It really is helping my project.

      Reply
  37. David says:
    Oct 17, 2013 at 9:48 am

    Hey Thanks!!

    I Have a cuestion.
    can i display this on a slider on the single page?

    Reply
    • WPBeginner Support says:
      Oct 21, 2013 at 7:15 pm

      depends on what code or plugin you are using to add the slider.

      Reply
  38. Joshua says:
    Sep 10, 2013 at 10:57 pm

    Hey, I’m trying to figure out how to turn this block of code into an array that can be used outside of the loop (in a foreach loop thats after the post loop).

    if (class_exists(‘MultiPostThumbnails’)) :

    MultiPostThumbnails::the_post_thumbnail(get_post_type(), ‘secondary-image’);

    endif;

    How would you do this? Great tutorials by the way!

    Reply
  39. Rajeev says:
    Sep 6, 2013 at 9:07 am

    Please give me idea to add two featured images from front-end using code.

    Reply
  40. Aura Ide says:
    Jul 19, 2013 at 8:28 am

    Thank you for this article as I was looking for a long time, it turns out I found here. We will practice immediately. The tutorial is very clear, good luck!

    Reply
  41. Travis Pflanz says:
    May 21, 2013 at 1:44 pm

    To improve on this idea, you could just use a custom meta box/fields plugin or create a custom repeatable field… To allow different number of “post thumbnails”

    Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
PushEngage
PushEngage
Increase your website traffic & revenue with push notifications. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2020 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2020)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2020)
    • SiteGround Reviews from 4196 Users & Our Experts (2020)
    • Bluehost Review from Real Users + Performance Stats (2020)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2020 – Step by Step Guide
Deals & Coupons (view all)
SendinBlue Coupon Code
Sendinblue Coupon
Get Sendinblue, a powerful marketing automation toolkit for small businesses, for FREE.
StackPath's logo
StackPath (MaxCDN) Coupon
Get StackPath CDN for just $10/month! It's the same service we use to make our site super fast.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).
Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress CDN by MaxCDN | WordPress Security by Sucuri.