Free Guide: 5 Website Fixes to Attract More Leads ✅ Download Now! ✅

Auto-Resize WordPress Featured Image and Crop if Necessary

If you are creating a WordPress site for a user, you want to make sure everything is as easy as possible for them. One trick that can make things easier is to have images automatically resize when they are used for a featured image in WordPress. Resizing images may be easy for developers and graphic designers, but some end-users don’t have the skills or time to resize an image to fit perfectly in your design. Luckily, this is simple to set up.

The Process

  1. Before we even start, make sure that your theme supports thumbnails. To do this just make sure the the following line of code is in your functions.php file. If you do not know how to access the functions.php file, see my post on how to access key WordPress theme files.
  2. add_theme_support( 'post-thumbnails' );

  3. The next step is to put the following line of code in the WordPress theme’s functions.php file.

    add_image_size($name, $width, $height, $cropBoolean);

    The add_image_size(); function has 4 parameters. $name is the name that you want to call your image with. $width is the width you want the image to crop to in pixels. $height is the height you want the image to crop to in pixels. $cropBoolean is a true or false parameter. If set to true the image will crop itself automatically.In the example below, the name I use to call the cropped image is “featuredImageCropped”. The height and width are 250px and 200px respectively, and the image is set to crop.

  4. add_image_size('featuredImageCropped', 250, 200, true);

  5. The next step is to reference the new image size in your theme. Place the following code wherever you would like to see your cropped image:
  6. the_post_thumbnail('featuredImageCropped');

Conclusion

There you have it. Now when you add a featured image to a post, the image will not need to be resized or cropped beforehand. WordPress will do it for you!

Free Download

Free Guide: 5 Quick Fixes to Get More Leads from Your Website

After 18+ years of building results-driven websites for business owners, I’ve learned what actually works.

This free guide breaks down five simple changes you can make this week to turn your website into a lead-generating machine. No redesign required.

5 Things Every Business Owner Can Fix On Their Website In The Next Week To Get More Leads

"*" indicates required fields

I take your privacy seriously – I’ll never share your information with anyone. Privacy Policy.