Code.Useful snippets for WordPress.

Thumbnail upscale & correct crop in WordPress

By default, the WordPress custom thumbnail size functionality hard-crops large source images into smaller ones perfectly well. However, you will run into size issues when the source image is smaller than the custom thumbnail size.

It can be fixed by adding this code to your theme’s functions.php file. It upscales images to fit all thumbnail sizes and crops them correctly.

The slight downside (not much to worry about with the server space we have today) is that if you for example upload a 16×16 favicon to your media library, it will be cropped and upscaled to all larger thumbnail sizes available. So, some more images will be created.