Add Post/Page Thumbnails

Ever thought about having a featured image on your posts or pages? Well, here it is. Add the following in functions.php and you will find a new meta-box in the edit page, that allows you to choose a featured image for the post.

Code Snippet:

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

// This adds support for pages only:
add_theme_support( 'post-thumbnails', array( 'page' ) );

// And this adds support for posts only:
add_theme_support( 'post-thumbnails', array( 'post' ) );


// To get the thumbnail in your post, you add the following inside the loop:
if ( has_post_thumbnail() ) {
	set_post_thumbnail_size( 400, 150 ); # width, height #
	the_post_thumbnail();
}
?>

Posted in Images, Pages, Posts