サイズのまちまちな画像を、同じサイズに切り抜きします。
サムネイルのサイズをfunction.phpに追記
「function.php」
// サムネイルのサイズ設定
add_image_size( 'small-feature', 300, 300, true );trueにすると縮小時に切り抜きを行います。
名前を下記にすれば、デフォルトの設定を上書きできます。
画像サイズを縦横0にすれば、そのサイズの画像は作成されません。
- ‘thumbnail’ //サムネイル (デフォルト 150px x 150px)
- ‘medium’ //中サイズ (デフォルト 300px x 300px)
- ‘large’ //大サイズ (デフォルト 640px x 640px)
切り抜き位置を指定
「function.php」
// サムネイルの切り抜き位置を「画像の一番上、左右中央」に設定
function my_awesome_image_resize_dimensions( $payload, $orig_w, $orig_h, $dest_w, $dest_h, $crop ){
    if( false ) return $payload;
    if ( $crop ) {
        $aspect_ratio = $orig_w / $orig_h;
        $new_w = min($dest_w, $orig_w);
        $new_h = min($dest_h, $orig_h);
        if ( !$new_w ) {
            $new_w = intval($new_h * $aspect_ratio);
        }
        if ( !$new_h ) {
            $new_h = intval($new_w / $aspect_ratio);
        }
        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
        $crop_w = round($new_w / $size_ratio);
        $crop_h = round($new_h / $size_ratio);
        $s_x = floor( ($orig_w - $crop_w) / 2 );
        $s_y = 0;
    } else {
        $crop_w = $orig_w;
        $crop_h = $orig_h;
        $s_x = floor( ($orig_w - $crop_w) / 2 );
        $s_y = 0;
        list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
    }
    if ( $new_w >= $orig_w && $new_h >= $orig_h )
        return false;
    return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}
add_filter( 'image_resize_dimensions', 'my_awesome_image_resize_dimensions', 10, 6 );プラグインでサムネイルを作り直し、不要なサイズを削除
投稿済みのサムネイルのサイズを変えるためにプラグイン『Regenerate Thumbnails』を使用します。
Regenerate Thumbnailsの使い方
メニューの『ツール』>『Regenerate Thumbnails』を選択
- 「Regenerate Thumbnails For All ○○ Attachments」
 (すべての画像)
- 「Regenerate Thumbnails For All ○○ Featured Images Only」
 (アイキャッチ画像のみ)
- Skip regenerating existing correctly sized thumbnails (faster).
 (正しいサイズのサムネイルの再生成をスキップ)
- Delete thumbnail files for old unregistered sizes in order to free up server space. This may result in broken images in your posts and pages.
 (未登録の古いサイズのサムネイルファイルを削除)
切り抜き位置の実験
このような画像を切り抜いてみます。



指定サイズより画像が小さいと、正方形に切り抜かれないようです。
