Snippet: Adding Post Thumbnail in WordPress 2.9

When surfing the Web, you can easily come across WordPress sites that associate an image thumbnail with each post. This is particularly obvious for those blog with magazine style layout. Before WordPress 2.9, the only way to do this is to insert a custom field with the URL of the image thumbnail in each post/page. Now this feature is built into the WordPress core and you can use it without using any custom field.

Firstly, in your theme folder, open the functions.php file and insert the following function to the end of the file.

    add_theme_support( 'post-thumbnails' );

Save and upload the file back to the server.

Now in your Post/Page edit section, you will find a Set thumbnail option in the rightmost column (just below the Categories section).


Click on it. The image uploader window will appear. You can either new image (or select from Gallery) the picture to be used as the thumbnail. Once you have uploaded, click on the use as thumbnail option.


Save the post.

Getting the thumbnail to appear in the front end

To get the thumbnail image to appear, you need to insert the function

if ( has_post_thumbnail() ) {
	    // the current post has a thumbnail
	} else {
	    // the current post lacks a thumbnail

in your theme files. The most likely place is index.php, single.php and page.php

Check out Mark Jaquith‘s article for more detail on the usage of the thumbnail function.


Damien Oh started writing tech articles since 2007 and has over 10 years of experience in the tech industry. He is proficient in Windows, Linux, Mac, Android and iOS, and worked as a part time WordPress Developer. He is currently the owner and Editor-in-Chief of Make Tech Easier.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox