Add Featured Image Support to a WordPress Theme
WordPress theme allows us to control many aspects of the design of their website.
One of the most common design feature in the theme is the image of the feature. Many bloggers like to use large, high quality images for their posts.
In this tutorial, we’ll show you how to add support images are displayed in a custom WordPress theme.
What is a WordPress featured image?
A featured image is a single image that the author chooses to represent a single blog in WordPress. These images are different from a regular image. As you may know, you can insert an image anywhere in the message that you deem appropriate.
Step 1. Add featured image setting in the dashboard
Edit the functions.php file of your theme and add the code below:
/* Add featured image setting in the dashboard */
function featured_img_support() {
add_theme_support( 'post-thumbnails' );
}
add_action( 'after_setup_theme', 'featured_img_support' );
With this code in place, we now have to look at the options screen in the WordPress editor to set the feature image. The images displayed are now enabled on our theme.

Step 2. Display the featured image in posts
We can start with the basics. All we want to do is to output the image features image in a blog post.
You can use <?php the_post_thumbnail(); ?>
Inside the while() loop add this code:
<?php
if( has_post_thumbnail() ):
echo get_the_post_thumbnail();
endif;
?>
The above code checks whether the image is to post / page and then prints with get_the_post_thumbnail() function.
Once the new code is integrated into the loop, it will look like this:
<?php
while ( have_posts() ) : the_post();
if( has_post_thumbnail() ):
echo get_the_post_thumbnail();
endif;
endwhile;
?>
Step 3. Check the output
- Create a new post.
- Add a featured image.
- Preview the changes:

Customize featured image sizes with add_image_size()
Let’s go a little further and are now adding support for several features of the image size using add_image_size() function. We will add this functionality to our functions.php file.
function featured_imgsize_support() {
add_theme_support( 'post-thumbnails' );
add_image_size( 'small-thumbnail', 100, 100, true );
add_image_size( 'medium-post-image', 300, 300, true );
add_image_size( 'square-post-image', 500, 500, true );
add_image_size( 'large-post-image', 720, 500, true );
}
add_action( 'after_setup_theme', 'featured_imgsize_support' );
You can add more image size according to your requirement.
How to use Customize featured image sizes in your post
Follow Step 2 instruction and change get_the_post_thumbnail(); to get_the_post_thumbnail(‘small-thumbnail’); for small thumbnail size. You can change code according to your size requirement.
After adding new customize feature images size code Setp 2 code looks like:
<?php
if( has_post_thumbnail() ):
echo get_the_post_thumbnail('small-thumbnail');
endif;
?>