Quick Tip: How to Use the New
videos

Quick Tip: How to Use the New “Post-Thumbnail” Feature in WordPress 2.9

Share

Up until the release of WordPress 2.9, setting up “post-image” support for your blog was a bit more tedious a task than it really needed to be. Luckily, that’s no longer an issue. I’ll show you how to get setup in this four minute video quick tip.

Step 1. Edit your Functions.php Page

// Enable support for post-thumbnails

add_theme_support('post-thumbnails');

// If we want to ensure that we only call this function if
// the user is working with WP 2.9 or higher,
// let's instead make sure that the function exists first

if ( function_exists('add_theme_support') ) {
	add_theme_support('post-thumbnails');
}

Step 2. Insert the Image Tag into your Loop

Within the “if have_posts()” loop, simply place this piece of code anywhere you like. At that point, WordPress will insert an image tag onto the page accordingly. Please note that you’ll have access to a “wp-post-image” class that you may then work with to format/style the image.

<?php the_post_thumbnail(); ?>

Related Posts

Add Comment

Discussion 66 Comments

  1. Jeffrey Way says:

    Just a note that I don’t think I clearly made reference to the fact that you don’t need to write “add_theme_support(‘post-thumbnails’);” twice in the screencast. I was showing an either/or type situation – see the written portion for more details. :)

    • You should have deleted that first “add_theme_support…” in the screencast after you made the second one, i think it’s gonna be a little confusing for beginners, because most of them won’t even check the text part of this post :)

    • eugene says:

      I might add that tutsvalley is a network which looks like a sloppy copy of envato network. Even name enavu is similar envato.

      • Damn that brown header. :)

        People tend to search for familiar things in something they see for the first time, that’s why you think it’s a “sloppy copy of envato network”.

        For sure, Envato is a role model to me but intention of copying it was never there and never will be.

        PS I published my tutorial a bit before Jeffrey so he is the one that copies. Haha. Just kidding Jeffrey :)

      • danny says:

        +agreed

        what an awful site and such a rip

        envato, enavu
        tutsplus tutsvalley
        codecanyon wpcanyon

        the enavu logo is made from a stock photoshop shape LOL
        even tried the dots in background from envato.

        seems to me like if you actually had the skills to do it it would of looked identical fortunatley you don’t as we can see.

      • Jeffrey Way says:

        Well technically my screencast was available on Screenr since yesterday….

      • The enavu network is not in any way a copy of envato :) we know the names are close.. cool. But we offer a much different set of services. Starting with free project management (freedcamp.com) and the newly released html5 css3 framework (52framework). Yes both networks provide web development tutorials… big whoop. And just for the record using those “dots” is a technique that envato does not own and has been around for years. But i will restrain myself from addressing the comment from danny about “skills”. I am sure he posses them to such an extent that we shall all bow to his mighty skills. At any rate, we are redesigning our logos because using stock photography was rather a quick resolution.

      • -agree

        We should not said he copied the post here, because this tip has already submitted on some blogs, not only this site. I saw more than 3 sites posted already and more than a month ago.

        However, the kicking ass here is Jeffrey did a great screencast.

      • @Lam – That was just a joke because we tweeted our new posts in the same time and their names ware exactly same. Twilight Zone…

        And enough of this. This is getting into a big offtopic. :)

      • Alec Gorge says:

        Correct me if I am wrong, but enavu.com said copyright 2004-2010, where envato has only been around since 2006, implying that enavu is older.

      • Jeffrey Way says:

        My best guess is that’s not true though.

    • @Alec – That’s correct. Enavu is registered as a web dev firm in US in 2004.

      • Trecoolius says:

        According to a whois query:

        Updated Date: 16-apr-2010
        Creation Date: 01-may-2009
        Expiration Date: 01-may-2013

        Kind of late for a “firm” established in 2004. How come that if you specialize in web dev you registered your domain 5 years later?

  2. Nic da Costa says:

    WOW great tut! Thanks! Am new to WordPress and am currently working on designing my blog and was wanting a feature like this!! Will definitely come in handy!

  3. Cedric says:

    Good new feature to know. But is there a way to only get the src value of the thumbnail, in order to combine it with a script like timthumb in a theme?

  4. Imon says:

    Great tutorial, will help when i need work with wordpress next

  5. Ed Baxter says:

    Great tutorial Jeff! I will be using this for my new blog in the next couple of days :) Shocked it took wordpress so long to support post images though!

  6. Nick Parsons says:

    Great, I had somehow missed this new feature. Thanks for taking the time to explain it!

  7. Can Aydoğan says:

    Great tutorial! I need “post-thumbnail”. Thanks

  8. curtis allen says:

    great tutorial jeff. Thanks for the tip.

  9. Kelly T says:

    Is there a reason this isn’t supported by default?

  10. Branson says:

    Great tut as always Jeffrey! This is such a useful feature for WP 2.9 that I cant believe it took them so long to implement.

  11. DesignLovr says:

    Thanks for this quick tip – up until now I didn’t know about this feature. Finally now more automated scripts or custom fields in order to get a proper thumbnail.

  12. Andris says:

    Great tutorial. Thanx for sharing it. I still use the old way. But I’ll definitely change that soon.

    $postThumbnail = get_post_meta($post->ID, ‘postThumbnail’, $single = true);

  13. designi1 says:

    Nice and simple tutorial!!! I made something equal at designi1… but i use the custom fields to make the thumbnail :D its almost the same process…

  14. Adam says:

    Thanks for the tut. WordPress keeps adding great functionality (probably because they listen to the developers). Open source rocks.

  15. Finbarr says:

    How do I go about making this work with the recent_posts function?

  16. Ciwan says:

    Thank You this was awesome :)

  17. Alexander says:

    Good stuff Jeff, I’m currently working on a wordpress site, this will be very usefull, thanks!

  18. David B. says:

    Another fine quick tip Jeff! Very helpful. Implementing this into my site as we speak. So much easier.

  19. Eric S says:

    To get my images on the archive pages and the home page to link to the post, I wrapped an anchor tag with the php with the permalink and this gets my viewer to the post easy enough.
    But on my single post file, I want to have that image open up to a full size of the image.
    WHY IS THIS NOT AN EASY THING? Am I missing something? I threw an anchor to the the_post_thumbnail (‘full’) but this does not work.
    Is there something I am not doing? Yes, I AM new to WP but not programming, coding or development and I would like this feature to work like this and it seems it should do it “automagically”?

  20. Matt says:

    What did you use to edit the CSS there?

  21. Great Tut…

    I was actually just speaking to client a day ago about how to make post-img easier.

    Thanks for sharing.

    As always you guys are awesome.

  22. Eric S says:

    CSS EDIT on that extension is awesome! I use Dreamweaver quite a bit myself for a lot of coding and CSS but you just cannot beat using that extension to see the immediate results and then copy and paste into your own stylesheets.

  23. Eric S says:

    Jeffrey, is there some easy way to make your single post thumbnail link to a full version of itself?

  24. Thank you so much,
    really, it’s work :)

  25. Evan Mullins says:

    Nice quick and easy. Thanks for the quick overview, helps a lot

  26. Syed Balkhi says:

    Perhaps a source link to Mark Jaquith’s site would be very handy. While you did a great screencast Jeff, you missed out the feature of having more than one size using the thumbnail by simply identifying that in the functions.php file.

    http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/

    Above is Mark’s article for anyone who is looking to use this feature on advanced templates. I just used it on a client’s site utilizing this feature and had 4 different sizes of the same image being generated.

    This function is very powerful only if WordPress adds the cropping ability for multiple sizes.

  27. Great tutorial.
    Was just workin on a wordpress site for a client. Might just add that before i complete it for Sunday.

  28. Ciwan says:

    Guys How do I make this work on other themes ! I am currently in the process of creating a theme for wordpress, but when I try this in the theme I’m creating I get the following:

    “Fatal error: Call to undefined function the_post_thumbnail() in /wp-content/themes/Elegance/index.php on line 8″

    I’d greatly appreciate some help.

    Thank You.

    • Ciwan says:

      Sorry I figured it out, I had to copy the [ functions.php ] file from the Default Folder to the folder of the NEW theme I was working on.

      Thanks again for this BRILLIANT Tutorial. :D

  29. Vira says:

    Jeffrey,

    Thanks for this tutorial. I had no idea of this new feature!

    Would you happen to know how to stop WordPress from automatically declaring the height and width of the image, so I can simply adjust it with only width in CSS?

    If that is possible, knowing how to change that would help me in other areas where WordPress makes something default that I’d like to change.

    Thanks again!

  30. probloggerid says:

    thanks a lot for this tutorial, it’s what i’m looking for my first theme in wordpress

  31. Angel A. says:

    Thank you, very easy to implement

  32. IPBrian says:

    Awesome…I will have to put this to some use coming up!

  33. Vincent says:

    How do I change the default class the image is assigned? When I choose a post image, it doesn’t automatically get assigned wp-post-image. The only class it gets is like alignnone, alignright, alignleft, depending on what alignment I choose. To add a class, I have to edit the image in the post again.

  34. TechDaring says:

    I want to know how to insert image for each of post to become thumbnail of that post. Using custom field with name post-thumbnail ?

  35. Dijux says:

    Great and simple code to use :) thanks guys. I was in battle just to pick the src of the image and resize it in the fly so this the simplest way.

  36. Rahul says:

    Thanks for the tutorial, that’s the one I was looking for.

  37. nandan says:

    Great Video Jeffrey. It helped me set this up in 4 minutes. Thanks again.

  38. bob says:

    How do you add lightbox or thickbox (example rel=”lightbox” or class=”thickbox” to the thumb?

  39. Belinda says:

    Awesome!

    When I added this to a blank functions.php file (ie not the default one) it sort of messed things up, so I ended up copying everything from the default one and it worked fine :-) Yay!

  40. pyemachine says:

    excellent tip as always

  41. Flepi says:

    Hi,

    Can we know what is the tools you use to edit css and have a live preview of your web page in the same time ?

    Thank you :)

  42. biber hapi says:

    Thanks Forower web pages

  43. biba says:

    Hello, I am a complete beginner so my question might sound strange to all you developpers but I just loaded the aparatus theme up and now I need to set the thumbnail function up, but where on earth do I actually include this first “step” in my functions.php ??? I simply tried to add it right in the beginning and got locked out of my page.. seriously, where do I put it in ? I don’t want to bother my hosting company again to get me in!
    thanks for your help, and the aparatus theme looks really georgous.. oh, another question, any suggestion on how to get rid of the “follow me on twitter button in the header?

    thanks so much

  44. thanks alot for you tip and i will use in my themes :)

  45. Adam Drelich says:

    hi there,
    what screen flow software have you used to record this video?
    by the way.. thanks for it!

  46. Thank you, I will surely use this for sure.

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.