Changing The Default WordPress Image Sizes

When you upload an image to a WordPress media library, WordPress will create and store a variety of different sized copies of it, by default these are called thumbnail, medium, large and full size. When inserting an image into a post you can select which size you want to insert:

You can alter these default sizes from the admin panel under Settings; Media like this. However, if you’re developing a theme you might want to do this from within your theme’s code in order to ‘enforce’ specific sizes on your users without requiring them to edit admin settings. For example, suppose you’re wanting to maintain a vertical rhythm in your pages by using a fixed line-height in your CSS (e.g. 18px). In that case you’re likely to want your images to conform to that vertical rhythm as well by setting their height to be a multiple of 18px. You can do this by adding the following code to your functions.php:

update_option('thumbnail_size_w', 144);
update_option('thumbnail_size_h', 144);
update_option('medium_size_w', 288);
update_option('medium_size_h', 216);
update_option('large_size_w', 480);
update_option('large_size_h', 360);

In future, that will result in the following settings when you insert an image:

Note that this will not affect previously uploaded images; they’ll still retain the dimensions they were uploaded with. There are various plugins available to convert them to your new sizes though.

Leave a Reply

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