How to add and Use WordPress Custom Image sizes

Categories: General

Adding a custom image size to WordPress could not be easier. The following will create a size called Square that is 150 by 150 pixels, the parameter true will result in the cropping of an image.

add_image_size('square', 150, 150, true);

Now any time an new image is uploaded WordPress will generate a file something like image-150×150.jpg.

If you want to be able to insert these images in your posts then you will need to register the size with the Media moda.

add_filter('image_size_names_choose', 'add_image_sizes_editor');

function add_image_sizes_editor($sizes)
    return array_merge($sizes, [
        'square'   => __('Square', 'axe'),

Now when you create a post and want to add an image your custom sizes will be available to you.

Adam Patterson

Adam Patterson

User Interface Designer & Developer with a background in UX. I have spent 5 years as a professionally certified bicycle mechanic and ride year-round.

I am a husband and father of two, I enjoy photography, music, movies, coffee, and good food.

You can find me on Twitter, Instagram, and YouTube!