Ultimate method to add post thumbanils to your wordpress theme

Wordpress Hacks

Wordpress Hacks

In this tutorial, I will show you the best method to add post thumbnail feature to your wordpress theme. This is what we are going to do.

  1. We will check if there is any image set in custom fields, if yes we display that image.
  2. Else we check if there is any image stored in the gallery associated with that post, if found we display that image.
  3. Else we do a pattern match for image url’s over the post content and extract the images used in the post, with this method we will be able to pull out images that are not part of wordpress gallery.

How to create a custom field?

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.

Adding post thumbnails using wordpress custom fields

Adding post thumbnails using wordpress custom fields

To add a Custom Field for a Thumbnail, just fill in the Key with “image”.  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.

Adding thumbnail to our post

Add the following code before
the_content() / excerpt()

2 thoughts on “Ultimate method to add post thumbanils to your wordpress theme

  1. [...] This post was mentioned on Twitter by Dicky Lim. Dicky Lim said: Ultimate method to add post thumbanils to your wordpress theme - http://bit.ly/1J6bny (via @gandham) [...]
  2. Nice Tutorial, Satish. But a more simpler method is to use the first image of every post as the post thumbnail. http://inforids.com/best-simplest-way-to-add-thumbnail-to-post-excerpts-in-wordpress-themes/