Add Feature Image Support Function in your WordPress Theme

Featured Images or Post Thumbnails is a theme feature. The majority of themes such as Genesis and also others support featured pictures by default. An easy means to find out whether your style assists showcased graphics is by going to the blog post editor. Just develop a brand-new article and scroll down a little to see if there is a meta box called feature image on the right hand side of the display.

You may have observed the “Featured Image” box when editing a post or page. It enables you to post or pick an associated picture for the short article. It generally appears as a thumbnail when seeing a list of posts, possibly in a classification index or search results page.

Feature image needs to be enabled within your theme. You can add it to a plug-in so it’s available to all themes but that may not be appropriate in every situation.

You can include feature image to your theme, If you are comfortable modifying theme data as well as understand your way around a little CSS, then you can do it on your own.
To add this function in your WordPress theme, you have to add this line of code in your theme’s functions.php (wp-content/themes/your-theme/)

1

add_theme_support(‘post-thumbnails’);

This code will enable featured photo assistance for posts and also web pages. You can now visit posts or web pages, and you will see feature image choice allowed. Nevertheless, when you establish a featured photo it will not automatically present in your WordPress theme. To show featured photos in your theme, you need to modify your templates and include this line of code where you would like to present the featured image

1

<?phpthe_post_thumbnail();?>

or you can add like this

1

2

3

4

5

6

7

8

<ahref=“<?phpthe_permalink();?>“>

<?php$pimg=get_the_post_thumbnail();

if($pimg){?>

<?phpecho$pimg;?>

<?php}else{?>

<img src=“<?phpbloginfo(‘template_directory’);?>/img/post-img.jpg”/>

<?php}?>

</a>

Advanced Feature Image Use

The above code is just basic way to add default feature image in your wordpress theme. you can create your own feature image function and set it to your own Feature Image Size which you want to display in your site.