How to Enable Featured Image in WordPress?

Featured Images or Post Thumbnails is a theme feature. Most themes such as Genesis and others support featured images by default. A great way to determine whether your theme supports featured images is by going to the post editor. Basically, make a new post and scroll down a little to see if there is a meta box known as featured images on the right side part of the screen.

Post Thumbnails

In this article, we will show you how to add featured images or post thumbnails in WordPress.

Enabling Featured image support

To add featured image support in a WordPress theme, you need to add this line of code in your theme’s functions.php file:

This will enable the featured image support for both post and for pages.

In case we need to add featured images support for post or page only then we can use following line of code in functions.php.

For Post:

For Page:

Display/Get featured images in WordPress theme

To show featured images in wordpress theme, you need to modify your templates and add this line of code where you want to show the featured image:

Set image size for featured images

To set your thumbnail using box-resizing:

To set your thumbnail using hard cropping:

Creating Multiple Sizes For Thumbnail Images
In some cases, we need different sizes of images. For example, If we need to display a hard cropped square thumbnail on category pages but a box resized rectangular header image within individual posts?

In that cases we need to specify additional custom sizes in functions.php:

In this above example we have added a custom image size called thumbnail-size with 590px with and 180px height. Now we can use below line of code to use this image size in theme:

Get URL of the Featured Image

Get Featured Image Url by Post ID

Or if you want to get the image by image size.

Leave a Reply

Your email address will not be published. Required fields are marked *