How to set dimensions of the post thumbnails (featured images)

How do I control the dimension for post thumbnails (featured images) on the homepage (blog) of my site?

Dimension for the post thumbnails need to consistently be 470px x 370px. I have tried adjusting the dimension in Settings > Media but this does not work.

My code:

     <div class="posts__post">

        <article>
             // post thumbnail in question
             <a class="posts__post--preview" href="https://wordpress.stackexchange.com/questions/239844/<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
             <p class="posts__post--tag"><?php the_category('&nbsp;/&nbsp;'); ?></p>
             <h1 class="posts__post--title"><a href="https://wordpress.stackexchange.com/questions/239844/<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
             <p class="posts__post--meta"><?php echo time_ago(); ?></p>
        </article>   

     </div>

I initially imported posts via the Codex theme unit test page and enabled featured images within my function.php file.

1 Answer
1

Add this code to your theme’s functions.php file. Images are resized by WordPress when they are uploaded. A plugin such as Regenerate Thumbnails can be used to ensure that source images have been properly generated if image sizes are changed after the initial upload.

// Sets the parameters for the post-thumbnail image size
// https://codex.wordpress.org/Function_Reference/set_post_thumbnail_size
add_action( 'after_setup_theme', 'wpse239844_image_sizes' );
function wpse239844_image_sizes() {
    set_post_thumbnail_size( 470, 370, true ); // $width, $height, $crop
}

Leave a Comment