X

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();
}
?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!