Tuesday, 10 November 2015

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

Share

& Comment

0 comments:

Post a Comment

 

Copyright © Taha Codes™ is a registered trademark.