How to add Featured image support to WordPress theme?
Author: WordPress Snippets | Posted on: June 4, 2018 |

Featured Images come after WordPress Version 3.0. Featured Image, is an image that is chosen as the representative image for your WordPress Posts, WordPress Pages or WordPress Custom Post Types. The display of this image is up to every WordPress theme.
All WordPress Themes have to declare their support for Featured Image before the interface for assigning these Featured Images will appear on the Edit Post and Edit Page screens. You can do do this by putting the code example in your WordPress Theme folder in your functions.php file. You can do this only if you don’t have Featured Image Element on your Edit Post, Page and custom post type screens
This is especially useful for “WordPress magazine-style” themes where each post has an image, you can use the WordPress Featured Image to display your post, page, and custom post types main image.
How to enable Support for WordPress Featured Image
add_theme_support( 'post-thumbnails' ); add_theme_support( 'post-thumbnails', array( 'post' ) ); // Your WordPress Posts only add_theme_support( 'post-thumbnails', array( 'page' ) ); // Your WordPress Posts Pages only
How to display your WordPress featured image in single.php file
<?php if ( has_post_thumbnail() ) : ?> <img src="<?php the_post_thumbnail_url(); ?>" title="<?php the_title_attribute(); ?>" alt="<?php the_title();?>" class=""responsive-class"/> <?php endif; ?>
In result of adding athe WordPress Snippet above in your WordPress Theme loop for single.php file you will display the following important elements with your Featured Image:
- Full path to your Featured image in src=”” element
- Alt text for your Featured Image
- Title text for your featured Image
If you want to recieve the latest WordPress snippets, tutorials, tricks and useful information about web development, seo, social media marketing, google you can Subscribe to our newsletter. All you need to do is to fill the Subscribe form below, verify your Free Subscription in your email and start read our daily useful tips and tricks straight in your mailbox.
Note* we hate spam and our newsletter is powered by Google Feedburner and you will not get spam messages in your mailbox.
Leave a Reply