Until now there was no feature in WordPress to allow you to post thumbnails, so we had to use custom fields or plugins or embed a picture inside the content to act as a thumbnail (that’s what i did when i first started with wordpress). The new version comes with that feature.
I assume you know what a post thumbnail is, you do know, right? Ohh ok, sorry, had to ask. Well let’s get to the point.
We will go through 3 simple steps in this tutorial.
- First – Activating thumbnail feature
- Second – Adding thumbnail to a post
- Third – Showing the thumbnail in a theme
1. Activating The Feature
Add the code bellow to the functions.php file in your theme folder.
add_theme_support(‘post-thumbnails’);
There is another function for thumbnails, and it’s used to automatically resize the image you set to be the thumbnail, so if you want your thumbnail to be exactly the same as the image you uploaded feel free to skip to second step.
That function is set_post_thumbnail_size(), which you call after the add_theme_support() function and if called, the image you have set as the thumbnail will be automatically resized. You can declare 3 variables inside of it, width, height and cropping. Cropping is set to false by default so it’s not required.
set_post_thumbnail_size(150, 100);
With the code above your thumbnail will be resized to approx 150px wide and 100px tall, keeping the aspect ratio. So the resized image will be closest to or exactly 150×100 which depends on the original size.
set_post_thumbnail_size(150, 100, true);
With the code above your thumbnail will be resized to exactly 150px wide and 100px tall, but you might loose a part of the image, because it’s cropped.
2. Adding Thumbnail To A Post
Go to your admin dashboard and either go to create a new post or edit existing one.
Notice: If you are creating a new post, first fill the title field so it can save the draft, otherwise you can’t add a thumbnail.
![]()
Click on the set thumbnail link, and you will get the same modal window like when you are adding an image. Now upload an image and when done you will see this.
![]()
Click the use as thumbnail link and in few seconds you will see the thumbnail tab gets updated with the thumbnail like on the next screenshot.
![]()
3. Show it
The code bellow is used to echo the post thumbnail image.
the_post_thumbnail();
But for example if you have a div wrapping the thumbnail, and you haven’t set a thumbnail for some post, then you will get an empty div. So it’s advised to run a little if statement to check if the post has a thumbnail.
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
Congrats, you have added thumbnails feature to your blog.
Some additional codes
Well, one more if statements is suggested, just to make sure the theme is running on WordPress version that can use add_theme_support() function which is introduced in 2.9. I’m not using it on my blog because i know i won’t downgrade it to an older version.
1. The activating
if ( function_exists( 'add_theme_support' ) ){
add_theme_support(‘post-thumbnails’);
//and add the resizing function here if you need it
}
2. The Showing
if ( function_exists( 'add_theme_support' ) && has_post_thumbnail()){
the_post_thumbnail();
}
You might also want to check a screencast made by Jeffrey Way on setting up and using the feature.
Final Words
That’s it, i hope you learned something from this tutorial. If i made a mistake somewhere or you think there is a better way to achieve some part feel free to say so in the comments.
Visit the best themes marketplace with over 600 premium wordpress themes.













I am pretty new to WP, so I don’t know anything other than having this awesome feature.
But, I don’t get how the heck or why the heck you cannot link the image of the thumbnail to a bigger image?
I made my archive pages and such able to be clickable. I wrapped the image with a link using the permalink for that post.
But on my single post, I would like that thumbnail to be able to be clickable and linked to a full size of the image.
I suppose I can just remove the thumbnail function on the single post page and then insert the image I want to enlarge on that post itself, but I think there should be some way to automagically have the thumbnail linked to a larger image of itself?
Am I missing something?!
I would suggest you to check out Digging Into WordPress, you won’t be anywhere near new when you finish reading this awesome book written by Chris Coyier and Jeff Star.
About the linking to the bigger image here is my solution (if anybody has a better one feel free to jump in).
1) Remove the set_post_thumbnails_size() part from functions.php
2) Inside index.php, search.php, archive.php and wherever you are showing a post thumbnail except single.php change “the_post_thumbnail()” to “the_post_thumbnail(array(180,200))”. That will resize it, so you don’t get the original size as a thumb.
3) In single.php put this code inside the “post looop”:
You can read a bit more about the snippet above in Get The Src Attribute From WordPress Post Thumbnail.
Now the thumbnail in single.php will be linked to your original image.
Hello…
Thank’s for this tut !
T think that we can make it more easy then this…
well, first we have to edit Functions.php by adding this:
add_theme_support('post-thumbnails'); if ( function_exists('add_theme_support') ) { add_theme_support('post-thumbnails'); }than we have to put on the loop function on index.php and archive.php and and and :
if ( has_post_thumbnail() ) { the_post_thumbnail(); }to cheek than make…
Sorry for my bad english… thank’s
I wasn’t aware that WordPress has this built in feature now. Thanks for sharing
Hi,
This feature is very interessting!
However, I haven’t find a way to add these post thumbnails by script : There should be a function like insert_the_post_thumbnail or set_the_post_thumbnail but haven’t found anything…
Do you have more info about that?
Add them by script? What do you mean?
I’m having a small problem where I set the thumbnail width and height on the TwentyTen theme (default theme for WP 3.0) like this:
set_post_thumbnail_size(206, 206, true );
And when I set the “featured image” the cropped thumbnail is still the default 940 X 198 pixels or whatever.. I can’t see what the hell I can be missing!
Did you make that change on line 116 in functions.php?
Or you can put this code(check bellow) on line 117 in functions.php.
and then where you want to show it call it like this
the_post_thumbnail('post-thumb-206');