WP Snipp Ninja

How to add Featured image support to WordPress theme?

Author: Dimitar Krumov | 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

About the Author

 Dimitar Krumov

Hello my name is Dimitar Krumov I am from Sofia Bulgaria but live in Varna on the Black Sea coast.I am a Web Developer since 2002 working in different Web Projects most of them are international and business-related. Some of my knowledge and skills but not limited to WordPress, HTML, CSS, Google Stack, Analytics, SEO and more..


Follow Dimitar Krumov on Social Media

Leave a Reply

Your email address will not be published. Required fields are marked *