Featured image was a nice feature that was introduced back in the WordPress version 2.9. Since then, it allowed you to choose a picture which would represent a post and make it even better and more interesting. But the image itself wouldn’t be automatically displayed in the post. That’s something a WP theme should handle.
We have already showed you how to make your authors use a featured images before publishing their posts. But before you can do that, you need to take care of your theme. Although most modern themes use featured images, you might end up with a theme without it. On the other hand, maybe you are working on your own theme where you want to include this neat feature. To make sure your theme can handle featured images, be sure to include this piece of code in your functions.php file:
add_theme_support( 'post-thumbnails' );
After you save changes done to your functions.php file, you are ready to see the results. Your posts and pages should now have a special box dedicated to featured images where you can select one from media gallery and attach it to that post/page. Still, this only links an image to a post, but your image won’t be displayed anywhere until you order WordPress to do so. Unfortunately, WordPress doesn’t speak human which means you have to handle a little bit more code.
To display that featured image, you will need this:
set_post_thumbnail_size( 120, 100);
The code should be written in the templates where you want your featured image to appear. Number in the brackets are used to define image width and height in pixels respectively. You should change the image size depending on your theme.
It’s not that hard to register and display a featured image, right? Now that you have tried this function and happily viewed your new post thumbnails, you are probably ready to register and display different image sizes.