WordPress Featured Image

In this WordPress tutorial we are going to see what is featured image and how to add this for a post. Featured images are used to have a rich look and feel. They can be used to display posts like a gallery.

For adding featured image to the posts we have to let the theme to support post thumbnail feature. With the theme’s support, WordPress admin will provide options in UI to add post’s feature image.

What is Featured Image in WordPress

Featured image is also known as post thumbnails. In WordPress version 2.9 when it is introduced this feature is called as post thumbnail and later in version 3 it is known as featured image.

WordPress Theme Support for Featured Image

The WordPress function named add_theme_support() is used to let the current theme to support Featured images. The following code has to be added in functions.php file.


Adding Post Featured Image

After enabling theme support we can see an option to add featured image for a post in its edit screen in Wp-Admin. The following image will show this administrative option.


After uploading featured images to the WordPress media library we have to set the uploaded image as a featured image or a thumbnail of the post.

WordPress Functions Show Featured Image

There are two functions in WordPress to get post’s featured image.

  • the_post_thumbnail() – It will display featured image.
  • get_the_post_thumbnail() – It will return a string containing the HTML code of the featured image.

Both of these functions accept two optional parameters, the thumbnail size and the image tag attributes. Before invoking post thumbnail functions WordPress has_post_thumbnail() is used to ensure that there is a featured image added for the post.

This Wordpress code tutorial was published on January 7, 2016.

↑ Back to Top