How to Add Featured Image Support in Custom WordPress Theme

WordPress is an amazing CMS for creating blogs and even websites. One of the major and most important part of a blog post is its featured image. You need to activate it for your theme.

function mytheme_post_thumbnails() {
    add_theme_support( 'post-thumbnails' );
}
add_action( 'after_setup_theme', 'mytheme_post_thumbnails' );

This will start showing the featured image block in your admin section.

Featured Image - WordPress Admin

Next step is to show the featured image in your theme.

You can do the same through following code:

while ( have_posts() ) : the_post();
    if( has_post_thumbnail() ):
        echo get_the_post_thumbnail();
    endif;  
endwhile;

You can skip the while loop if you are already in the loop.

One Comment

  1. Pingback: Wordpress - Get featured image - the_post_thumbnail | Webolute Blog

Leave a Reply

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