In this tutorial, I’ll show you how you can easily add thumbnails, lead image, and other extras to individual posts in Wordpress. These images can be shown on the front page, archives, search pages, etc – but appear outside of the content, giving you full control of their placement and style.
What Are Custom Fields?
If you’re reading through this article, there’s a possibility you’ve never heard of Custom Fields (or maybe you just haven’t seen a use for them yet). Essentially, all a Custom Field does is allow you to add extra pieces of data to individual Wordpress posts that otherwise aren’t there by default. In other words, along with things like the Post Title, Entry, and Categories, you could add:
- Thumbnail
- Lead Image
- Price (perhaps each of your posts is a product that you need a price label for)
- Source Link
Sure – but you COULD also just put those in the post… right?
Of course, but when you do that, you’re stuck with your default posting format and styling. What if you want to have a Thumbnail for your post, but instead of the thumbnail appearing inside of the post entry, you only want that thumbnail to appear on the front page of your blog – and using a completely different style than it would in your entry?
This is where Custom Fields come into play. They allow you to add as many additional fields as you like, all of which can be used anyway you want to use them.
Adding a Custom Field
The first step to making custom fields work is to actually add one to your Wordpress Blog. To do this, simply start making a New Post, and scroll down the page until you see “Advanced Options“. Under this heading, you should see something like, Excerpt, Trackback, and Custom Fields.

To add a Custom Field for a Thumbnail, just fill in the Key with “Thumbnail”. For the Value, post the full URL of the thumbnail you would like to use.
Click Add Custom Field, and it will apply to that post.
Creating Thumbnails for your Posts
Now that you have a key called Thumbnail, you’ll never have to create that key again. It’s stored so you may select it from the dropdown box for now on.
In each post that you’d like to have a thumbnail, you’ll have to go to the Custom Fields area of your Write Post page, select “Thumbnail”, and fill in a value with the path to the thumbnail you’d like to use.
Now, let’s insert this thumbnail into your post listings on the front page.
In your theme files (I am assuming that you have a basic understanding of modifying themes in Wordpress), open up index.php. Find these lines:
<?php while (have_posts()) : the_post(); ?> ... <?php endwhile; ?>
The code between these lines is the output for each individual entry shown on the front page of your Blog. So, let’s say you limit your blog to 10 posts per page, this is the code the repeats 10 times to display those 10 posts.
Within these lines, we want to add the following code in order to show our newly created thumbnails:
<img src="<?php echo get_post_meta($post->ID, "Thumbnail", true);?>" />
This outputs an image, using the Value of the Key, Thumbnail, which we’ve inserted into our post. It can be inserted ANYWHERE within the while loop, allowing you to float it to the left or right of the header and entry, display it above an entry, below, whatever you want.
Great, but I want this to show up In the Individual Post Too
That’s possible as well, using the same code as shown above. You just need to make sure you insert the code that displays your thumbnail in the while loop.
Maybe you want to display a different image on your post page, such as a larger or smaller version of your thumbnail. At Tutorial9, we often times have Lead Images at the top of our posts which are much larger than our thumbnails. This is very easy to achieve as well.
On your Write Post page, add another Key to your Custom Fields called “Lead Image“, with a value pointing to the URL of your lead image.
Now, in your single.php theme file, insert the following code inside of the loop:
<img src="<?php echo get_post_meta($post->ID, "Lead Image", true);?>" />
Simple!
Only Show a Thumbnail or Lead Image on Some Posts
Maybe some of your posts don’t require thumbnails or lead images. We don’t want to output unnecessary code… With a few additional lines, we can fix this problem.
First off, we’ll want to put this right after the loop starts:
<?php $Thumbnail = get_post_meta($post->ID, 'Thumbnail', $single = true); ?>
This won’t output anything in HTML, but will store the value of our Thumbnail field in a variable called $Thumbnail. If the field was left empty during the post creation process, this variable will also be empty.
Next, we need to modify our output a bit:
<?php if($Thumbnail !== '') { ?>
<!-- Any special styling you might have for posts with thumbnails... -->
<img src="<?php echo $Thumbnail;?>" />
<?php } ?>
What this does, is checks to see if the Thumbnail variable is empty. If it isn’t empty, the code will output the thumbnail image. However, if it is, nothing will be shown here.
After you’re finished modifying your code, upload, and test to make sure thumbnails are being displayed properly.
Free Goodies. Delivered to You.
Subscribe to Tutorial9, and we'll deliver you the newest freebies and tutorials for free.
Subscribe By Email Subscribe By RSSWith the help of these structured lessons, you'll be a master of Photoshop in no time!
Write for Tutorial9
- Do you want to get paid $150 for writing at Tutorial9?
- Are you a talented Photoshopper, Blogger, or Photographer?
- Want to help thousands of others by sharing your knowledge?
If so, we're interested in you, and we'll pay you. Find out how to write for Tutorial9.


125 Comments Leave a Comment
Great post! I’ve been wondering what the potential of custom fields are. I’ll definitely have to try it out. Thanks!
Would this also work with videos? Could you have a custom field to resize a video for say a featured video section and have it link to a full size version of the video?
This is the standard response (-:
1. Tell you how awesome and helpful your site is.
2. Tell you how awesome this actual tutorial is.
3. (Optional but worthwhile sometimes . . .) Tell you how awesome you are.
*Phew* Now I can ask a question:
I used your advice, but now I get nice little blank boxes above all my posts. What’s to be done?
http://www.oletoday.com/wordpress
Thanks for your help,
ZAK
wow… thanks for explaining this in English! i think this overview was the cleanest explanation i’ve heard so far- great post
i’ve been going crazy trying to figure out how to get a gallery of thumbnails for my photoblog, i thought this looked promising but it’s not clickable, the thumbnail, it doesn’t take you back to the post, so what, what????
This can be achieved by adding some simple html like this in your index.php:
<a href="” rel=”bookmark” title=”Permanent Link to “><img src="ID, “Thumbnail”, true);?>” width=”150px” style=”border: 2px solid #dfdfdf; float: right; margin-left: 10px;” />
Ive been working on different open and closed source CMS’s for over 7 years, in a way it became for me a hobby to test all of them all the time.
Wordpress, is a very easy to install, yet very simple to use CMS, in fact you can learn how to publish articles within less than a minute.
What i hate about this CMS that its extremely limited and you require to hardcore insert cods into your script files inorder to do something so simple like adding thumbnail to your article.
comparing to other available CMS’s i will give it 3 out of 10, and these marks focus on its simplicity and effectiveness in publishing articles.
I want add custom field to category. How it can be achieved?
If I don’t want to add a thumbnail to a post, how can I make it so the space doesn’t show up?
Thanks for the tutorial, Helped me
Great post, easy to read and implement
Hi, Great Post. Really helped me with setting thumbnails.
I did have a question though. I’m using the Arras Theme. I’ve been successful at making a post and having a thumbnail of that post show up on the main page in the galleries.
But what i can figure out is how to make it so that the thumbnail Only shows up in the main page, but not show up in the individual post?
Please help.
Thanks!
Yeah, I’m having the same issue
found this at http://code.google.com/p/arras-theme/updates/list and it worked
(don’t force thumbnail into post header) reported by m…@gogulski.com – This should really be an option rather than a forced item. local patch that turns it off at http://www.fr33agents.com: filters.php line 103: //$postheader .= ”;
This should really be an option rather than a forced item. local patch that turns it off at http://www.fr33agents.com: filters.php line 103: //$postheader .= ”;
And if you just want the thumbnail to show up in the meta data you can just add this to header.php in the section:
<link rel="image_src" href="ID, "Thumbnail", true);?>" />
Excellent, that worked first time for me, I have been playing around adding widgets and apps trying to figure this out having no idea that it was such a simple job. The more I experiment with Wordpress and customise it, the more I love the platform. Every minor problem or niggle I encounter is usually just my not knowing that there is a simple solution ready made and built in already.
Oh – just to follow that one up – here is a neat little extra bit of PHP for the thumbnail on the front page whichs adds a link to the article page:
<a href="”><img src="ID, “Thumbnail”, true);?>” border=”0″ style=”padding:0px 10px 10px 0px;” align=”left” border=”0″ />
Simple, but effective
I added the code line but it’s not working. I see on your blog is going well.
So i kind of replace the one given here in the post with your , in the index.php ?
Hi, my thumbnails are showing up on top of my posts on my homepage. How do I get them to show under the post title and to the left of the excerpt?
Thanks for any help!
Jen
I am trying to put thumbnails on the front page of all my recent posts. Finally, I find someone that can tell me how to do it…thank you. But, after using your advice, now I get nice little blank boxes above with a little red X above all my recent posts and no thumbnail. What’s am I doing wrong?
http://www.writing-freelance.com
PS-I bought this recently from someone else.
I’ve been looking for something like this for a while now…..thanks for a good article!