How To Keep Multiple Featured Images In WordPress Blog Posts ?

Using Multiple Post Thumbnails plugin you can add multiple thumbnails (featured images) in your WordPress blog posts. The plugin is specially created for bloggers who wants more than one Featured Image on a post.

Installation & Usage: Install and activate Multiple Post Thumbnails plugin. After activation open your theme’s functions.php register a new thumbnail for the post type you want it active for. If post_type is not set it defaults to post.

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

Display the thumbnail in your theme. e.g. for loop templates (outside of the loop, the first argument to MultiPostThumbnails::the_post_thumbnail() will need to be the post type):

<?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image'); endif; ?>

You can register the same thumbnail for multiple post types:

You can loop through an array of the post types:

        if (class_exists('MultiPostThumbnails')) {
            $types = array('post', 'page', 'my_post_type');
            foreach($types as $type) {
                new MultiPostThumbnails(array(
                    'label' => 'Secondary Image',
                    'id' => 'secondary-image',
                    'post_type' => $type
                    )
                );
            }
        }

There are more code snippets you can use with this plugin like yo can add custom thumbnail size in you theme etc, refer to its FAQs page.

Leave a Reply

Your email address will not be published. Required fields are marked *