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

How to Add Multiple Post Thumbnails / Featured Images in WordPress

Last updated on by
Follow WPBeginner on YouTube
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.


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »
  • Masood

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

  • gunadi

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

    thank’s :)

  • Mehdi

    Hi, Thank you for your work :)

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

    Thank you.

    • http://www.wpbeginner.com/ WPBeginner Support

      Yes you can.

      • Mehdi

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

        • Mehdi

          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.

  • Steve

    Great article!

    Just what I’ve been looking for.

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

  • abid

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

  • abid

    how to add upto 5 or 6 features images…?

  • abdul

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

    • http://www.wpbeginner.com/ WPBeginner Support

      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.

  • Gunaseelan

    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
    }

    • http://www.wpbeginner.com/ WPBeginner Support

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

  • Eoghan

    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?

    • http://www.wpbeginner.com/ WPBeginner Support

      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.

    • wgoodman

      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.

  • David

    Hey Thanks!!

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

    • http://www.wpbeginner.com/ WPBeginner Support

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

  • Joshua

    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!

  • Rajeev

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

  • Aura Ide

    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!

  • Travis Pflanz

    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”