Adding Featured Image Support To WordPress

So after WordPress Version 2.9, the featured image feature of wordpress has been a very big part of a lot of themes. However, it doesn’t just automatically work with every single theme. Every theme must first add the support for the feature, and that’s what we are going to go over today.

So the first thing we’re going to do is activate the feature. This is a simple edit to the functions.php of your current theme. Just ad

add_theme_support( 'post-thumbnails' ); 

Make sure to be inside of the PHP tags

<? add_theme_support( 'post-thumbnails' ); ?> 

Make this the very last line of the functions.php if you are unsure what to do.

Now when editing posts and pages, you’ll have an option on your right hand side to set a featured image. (if it doesn’t show up, check your screen options in the top right corner and make sure featured image is checked)

Now inside of your single.php, or page.php where ever you want the featured image to display you simply add the function post_thumbnail(); to the template, inside of the wordpress loop.

It would be a good idea to check if we have a featured post to work with, and only if we do try and echo it. So our code snippit will look like

if ( has_post_thumbnail() ) {

make sure that it’s inside the wordpress loop, a very plain example will look like

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
if ( has_post_thumbnail() ) {
<?php endwhile; ?>

For further details on how to work with the_post_thumbnail, check out the wordpress codex documentation here : http://codex.wordpress.org/Post_Thumbnails