For our theme to display featured images, we need to follow two steps – adding a new function for featured image support to functions.php
, and then add some code to display the featured images to our template files.
functions.php
file.?>
PHP tag, add the following code:add_theme_support( 'post-thumbnails' );
functions.php
file.index.php
file.<div class="entry-content">
and above the PHP call for the content itself.<?php if ( has_post_thumbnail() ) { the_post_thumbnail('large'), } ?>
page.php
file and repeat step 2 to step 4.We added the code needed to display featured images for each post and page. Let's look at that code in detail:
large
sizeNow let's add some featured images to our site and see how they look.