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.

159 Comments Leave a Comment
I’ve created thumbnails using that NextGen plugin and place a URL of it as the value. However sometimes thumbnails show up and sometimes they don’t. Mostly depending on browsers.
I’ve recreated the thumbs a few times and cleared the cache. I’m sort of fishing around the internet to see if anyone has experienced thumbs that appear and disappear.
Any suggestions?
i am reading your post and i love how u explain things. u are wicked, contact me if you want 10 bucks.
peace.
i ain’t joking here
I’m using the streamline theme and had no luck. All it does is show a clickable text link of the title of the post itself, rather than the thumbnail i want…
any idea what i’m doing wrong?
I could not get the dang POST THUMBNAIL thing to work and I noticed after the picture gets “crunched” where you pick the size of the thumbnail and such, there is a text link that says USE AS THUMBNAIL or similar, and you have to click it. Once you do, you will see behind the modal overlay, your image posts in that area of the POST THUMBNAIL
Thanks for the help. I am fairly new to WP but with your help I am learning quickly.
Great tutorial, thankyou. I was wondering how much more complicated it would be to insert and random image from a folder if there was no thumbnail added to the post? Say just a bunch of generic ones, similar to those on the comment system.
W
I used this code in index.php
<img style="margin:15px;"align="right" src="ID, “thumbnail”, true);?>” />
It appears great on index.php but when you click to read the post the image does not appear. Why not please?
wow Great article, thanks!
Great post . Thanks147
thanks for sharing. So mush121
We are Solution Provider for HVAC & R Segment in any Industries. We are into trunkey Projects, Precision, Air-Conditioning, Process Chillers, Hot & Cold insulation, HVAC Services like AMC with operation.For more information contact +91-7926423303 Email:sales@mkengineer.com.(rs090d389)
thanks for sharing. So mush128
Great article but why does the thumbnail show above the title ? How would I fix that?
Thanks for the Explorer tip