How to Change Thumbnail Crop Position in WordPress

Cropping function is called image_resize and it is located in media.php.

Step1. Open media.php file under wp-includes folder.
Step2. Find the function named “image_resize_dimensions” (Around line 309). Unfortunately this function is not pluggable and doesn’t use any hooks so we will edit it directly. Find the lines:

1 $s_x = floor( ($orig_w – $crop_w) / 2 );
2 $s_y = floor( ($orig_h – $crop_h) / 2 );

Step3. Those two variables define the start point of crop that will be used. Here is a sample image that will be cropped with those variables shown:

wordpress thumbnail cropping position

Step4. If you want top of part of the image as post featured image then $s_y value must remain zero. So we change that line to:
view source
print?
1 $s_y = 0; //floor( ($orig_h – $crop_h) / 2 );

Step5. Save the file and upload it to wp-includes folder.

Last Step. A post image is cropped at the first time it is uploaded. To update thumbnails you need this great plugin called Regenerate Thumbnails. This plugin takes post thumbnails and crops them again using your latest media settings. After you install it click on the “Regenerate All Thumbnails” button under tools. It will automatically crop all the post thumbnails again. This will take a minute or two depending on your server and number of posts you have. After the regeneration is complete all your thumbnails will be cropped from top.

From: Shailan.com

Leave a Reply

Your email address will not be published. Required fields are marked *