Today we discuss one useful topic related to Featured image in wordpress. In wordpress featured image also known as Post Thumbnails. Today most wordpress theme support post thumbnails. Church themes, Restaurant themes, WordPress photography themes and other types of themes have built-in support for post thumbnails. In this article we discuss How to add featured images or post thumbnails in wordpress.
Most wordpress theme support featured image default. In blog add featured image in each post it looks very attractive and can catch information very easy.
Theme Developers Guide to Featured Image and Post Thumbnails in WordPress
To add featured image in wordpress post we simply click on “Set Featured Image” link inside the featured image meta box shown in the screenshot above.
But we don’t know how to visible this featured image in wordpress theme. First we move to how to add featured image in wordpress theme.
To add featured image support in a WordPress theme, you need to add this line of code in your theme’s functions.php file:
add_theme_support( 'post-thumbnails' );
This code will enable featured image support for posts and pages. You can now go to posts or pages, and you will see featured image option enabled.
Adding Post Thumbnail or Featured Image in WordPress
To add featured image in wordpress post we simply click on “Set Featured Image” link inside the featured image meta box shown in the screen shot above. After clicking “set featured image ” it will open the wordpress media uploader.
This will open the WordPress Media Uploader. You can use that to upload an image from your computer or use an existing image from your media library. Once you select the image, simply click on Set Featured Image button.
The image will appear in the Featured Image meta box, like this:
To display featured images in your theme, you need to edit your templates and add this line of code where you want to display the featured image
To set image size for featured images you upload, you need to add this line of code to your functions.php file.
set_post_thumbnail_size( 50, 50);
You can also set additional image sizes to use with the_post_thumbnail() function. For example:
add_image_size( 'single-post-thumbnail', 590, 180 );
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.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.