How to show scaled featured image in template?

You can create custom size image with add_image_size() in the functions.php

function add_custom_size_images() {
    // Add image size width 300 with unlimited height.
    add_image_size( 'featured-image-300', 300 );
}
add_action( 'after_setup_theme', 'add_custom_size_images' );

And in the template to get the size that you created with the_post_thumbnail()

the_post_thumbnail( 'featured-image-300' );

Notice: If you want it to work with the old images that you uploaded already you need to regenarate the thumbnails. There are some plugins for this.

Plugin for example https://wordpress.org/plugins/regenerate-thumbnails/

Leave a Comment