Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Featured images, or post thumbnails, is a great function built into WordPress that in my opinion is not used nearly enough. Using featured images you can do all sorts of cool stuff like creating featured content sliders, add image previews, and indexes, and even make post galleries. Featured images can also be configured to interact with social sharing sites like Facebook and Google+ so that you can control what image appears when someone shares your content, because featured images are so powerful it's important that you understand how to add the image sizes you want and how to use them.
Let's first look at how featured images are configured. If you look at the twentytwelve theme the way it is now, you can see that there is a featured image at the top of each post. To assign a featured image you go into edit the post and you scroll down and here on the right side you have the Featured Image option. By default, the featured image appears at the top of each post, and if you go into the index and if you go into the index and you find a post that has a featured image, the featured image appears in the index as well. But what if you want to use a different-sized featured image? In that case you have to tell WordPress what size you want and how you want WordPress to handle that image.
To explain that a little better, I have to show you what happens when you upload an image to WordPress. What happens when you upload an image to WordPress is actually the WordPress takes that image and creates bunch of different versions of that image depending on what sizes are predefined. If you go into your WordPress installation and navigate to the wp-content folder, and then to uploads, and one of the folders under uploads, you'll find all the images that have been uploaded to your site. What you notice is first you have the image itself--this is the original--and then you have a series of different versions of that image in different sizes.
Here you have one for 150 x 150, one for 300 x 242, one for 370 x 300, one for a 1000 x 288, and one for 1024 x 829. These sizes are defined either by the theme or by the media settings inside WordPress. If you want to know where these sizes are defined, look no further than the media settings inside your WordPress installation. If you go to Settings > Media, you can see that here we have a defined size for Thumbnail size.
It's 150 x 150. We have a Medium size which is a Max Width of 300 and a Max Height of 300, and you have a Large size, which is a Max Width of 1024 and a Max Height of 1024. If you look at these image sizes again, you start seeing what's going on. An image is uploaded and then WordPress creates a 150 x 150 version, one that's 300 pixels wide, one that's 300 pixels tall, one that's 1000 pixels tall, and one that's 1024 tall or wide. But these sizes that are defined inside WordPress admin can be changed at any time.
When you are working with a theme and you want to include featured images in your theme you want to predefine the size of that image, and you want to make it so that no one can change it, because otherwise things might break. Adding new image sizes is done in the functions.php file, just like adding pretty much everything else is. To add a new image size I'm going to go to functions.php in my child theme, find this mychildtheme_setup function I already created, and here I am going to register a new image size.
It's very simple. You simply say add_image_size. Then you have to give your image size a name, so I'm going to call this category-thumb, and you have to define the size. I want this one to be 100 pixels wide and 100 pixels tall. And you have to say whether or not you want WordPress to crop the image. If you set it to false, WordPress will not crop the image, but instead squish it, which always looks really strange, so instead, I'm going to set it to true.
When I save this, what will happen is next time I upload an image to WordPress, WordPress will create an image that's 100 x 100. However, it doesn't automatically do that to the images that are already in the system. To make that happen I have to add a plugin that'll go through all the images and create the new size. So now I need to go to Plugins, add a new plugin, search for regenerate, and here you'll find a plugin called Regenerate Thumbnails created by Viper007Bond.
I'll install that one, activate the plugin, go to Tools, click Regenerate Thumbnails, and then click Regenerate All Thumbnails. Now, depending on how big your site is and how many images you have, this might take a really long time. You see, I only have 38 images and it's already taking a bit of time, so if you have a gigantic site, you may want to do this in several rounds. Once the process is complete, we can go back to the Uploads folder, and you'll see that now each of the images has a 100 x 100 version in addition to the ones that are already there.
That's because now we have regenerated a new image size for each of the individual images. I use featured images all the time in my themes, both for myself and for my clients. Now that you know how to add new sizes, I'm sure you're starting to get ideas about how to use this feature, and that's what we're going to do next.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.