WordPress: How to set post thumbnail (featured image)?

2012-07-23 WordPress

Post thumbnail is a feature, that allows to assign a picture to a post. This is better than inserting picture as a part of post’s content because You can easily obtain this picture from post data by using function:

<?php the_post_thumbnail( array(), array('alt' => '', 'title' => '') ); ?>

Next advantage of this feature is, that You will decide, that You don’t want this picture to appear, You don’t have to edit content of every post – just modify the part of template that shows thumbnail icon. By default, this feature is turned off. To switch it on, just open Your functions.php file and add the following code:

if (function_exists('add_theme_support')) 
  add_theme_support('post-thumbnails', array( 'post', 'page' ) );
  set_post_thumbnail_size( 300, 300, true );

Now, when adding or editing page, You should see new section called “Featured Image”.

Dimensions (width and height) are set in my case to be 300 pixels. Change it to value that will suit You and then, in specific template, use “the_post_thumbnail” to get Your thumbnail. Additionaly You can change the appearance by modyfying the CSS class of thumbnail image. I like rounded – check post with featured image.

Do NOT follow this link or you will be banned from the site!