Add Thumbnail to Post Using 2 Different Methods

Ever wanted to learn how to add a thumbnail to your WordPress post? In this tutorial I will go over the basic fundamentals of adding a WordPress thumbnail to your post. We will use two examples in this tutorial.

Adding the thumbnail code

Adding a Thumbnail to your WordPress is very simple and easy. To add a WordPress thumbnail to your post you would simpley add the code below to your index.php file.

add to index.php

The code above tells WordPress to get the thumbnail through a custom field. So to retrieve our image we would simply add the word “Thumbnail to our custom fields ”
add thumbnail

Styling the thumbnail is very simple. Depending on where you would like your image you would float the thumbnail to the left to align it on the left side or float it to the right to align it on the right side.
add to index.php

Changing the width and height of the thumbnail is quite easy also. To change the height and width you would simply go to the css and edit the height and width.


I know as a developer when I design themes for clients I try to limit the amount of code in my files to make it easier for the client to edit or get something.
In this method we will use our function.php file. Open your function.php and place this code inside

What the code above does is call your thumbnail through your functions.php file then it searches for the one line code in one of your WordPress templates. Usually the index.php file.

add to index.php

Retrieve the image using the code below. The code below automatically retrieves an image from your post and turns it into a thumbnail ( Should be placed in your index.php template file)

<img src="<?php echo retrieve_my_thumbnail() ?>" alt="thumbnail"/>

That's it! Please share with your friends.

Joe Granados the author

Joe Granados is the owner of WebDevTuts. He is also a web designer & developer who loves to design and develop websites. If you're looking for him you can find him via @webdevtuts

Leave a Reply