Crop Thumbnails From the Top Instead of the Center
Makes WordPress crop square thumbnails from the top of each image rather than the middle, so heads in portraits and headlines in screenshots are not cut off.
Opens WPIDE on
Code
// Cropped image sizes that should keep the top of the image.
$wpide_top_crop_sizes = array( 'thumbnail' );
add_action( 'after_setup_theme', function () use ( $wpide_top_crop_sizes ) {
foreach ( $wpide_top_crop_sizes as $size ) {
$sizes = wp_get_registered_image_subsizes();
if ( empty( $sizes[ $size ] ) || empty( $sizes[ $size ]['crop'] ) ) {
continue;
}
add_image_size( $size, $sizes[ $size ]['width'], $sizes[ $size ]['height'], array( 'center', 'top' ) );
}
}, 100 );
Notes
Applies to new uploads; regenerate thumbnails to update existing images. Also works for other cropped sizes listed in $wpide_top_crop_sizes.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.