In this WordPress tutorial, we are going to see what is featured image and how to add this to 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.
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.
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 a file
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.
There are two functions in WordPress to get post’s 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.