Creating New Image Sizes

WordPress makes several different sizes of every image that gets uploaded, but what if you want some new, custom sizes? Here’s a really simple way to add them with code!

This workshop references two plugins that can install from the WordPress plugin directory, you can see these workshops for how to install and use them: Pluginception and Regenerate Thumbnails.

Learning outcomes

  1. Know what the default image sizes are in WordPress.
  2. Understand how to create new image sizes.

Comprehension questions

  1. What are the default image sizes in WordPress?
  2. How many custom image sizes can be made?


Hey folks, welcome to another HeroPress Tip of the Week. This week we’re going to talk about how to add new image sizes to WordPress.

By default, when you upload an image, WordPress keeps the original and makes several new sizes.

And we’re looking right here at the settings page in WordPress under ‘Media’. And here you can decide what size your thumbnail, medium, and large sizes are.

You’ll note that thumbnails, you have the option to crop them to be completely square. Otherwise, it will go to the first dimension that meets this number.

So you could have one that’s 300, wide and 600, tall, or 300, tall, and 500 wide. So you can easily change these here.

But what if you want another one, what if you need all three of these and you need another one or another five, I’m going to show you how to make that you’re not allowed to reuse the names of these, you could change these programmatically.

But if you’re going to make a new one, you have to give it a new name. There are plugins that let you make these, I’ve never found one that I really liked.

And it’s so easy to do with code that I’m just going to show you how to use a function called add_image_size. It wants a name, width and height and whether or not to crop it.

And that’s kind of all there is to it.

The cropping can get a little confusing. So there is a link right here. This is the docs page on

That goes to this page, which shows you what different crop commands do.

So soft crop, you put in ‘false’ here, and you tell it 200 by 200, you’ll end up with this kind, however, you put it in hard crop ‘true’, and say 200 or 200, you’re going to end up with this kind of thing.

You can also put in an array. And you can say things like crop 200 or 200. But start in the top left instead of the center, that sort of thing.

So you can get a lot of options here. I recommend reading through this, you might need to experiment a little bit as you’re making new images.

So I’m going to show you how to make a new one. There’s some excellent code right on this page. This is good right here. So I’m going to grab that. Then before we get started, I’m going to show you I have these images uploaded this one is 1376 by 1032.

This was 2560 by 1440, 1920 by 960, 1920 by 1280, and 1024 by 768. So we’re gonna make a new one that is 800 wide by 600 tall. And let’s get creative.

Let’s do 800 by 400. And we will not crop first. So I’m going to go…I have Pluginception installed. So I’m going to create a new plugin and call it ‘Topher’s Image Sizes’. And version 1.0. Author Topher, we’ll just run with that. There we go.

So I’m pasting in the code that I took from the docs. So let’s look at what’s going on here.

There’s a function and it’s called ‘wp_docs_theme_ setup’ I’m going to call it to tophers_image_sizes and that’s unlikely to get stepped on by somebody else.

So tha’s that in there…then theexample here is making two image sizes 300 wide with unlimited height, and then 220 by 180 cropped. I don’t want that.

I’m going to call mine topher800. We’ll make it 800 wide. And I said earlier 400 But we’ll just leave it at 800 like this.

So then there’s an add_action that runs after theme setup. And it just runs this function and adds those image sizes. And that’s all there is to it.

So we’ll hit ‘Update file’. Now, something very important to note is that did not do anything to the images I already have uploaded. You can actually see them here on my file system.

There’s the 150 by 150. There’s one that is…come on Mac OS, you can do it…there we go. 300 by 225, 760 by 576, and 1024 by 768. And then there’s full size, which was 376 by 1032.

So I don’t have new ones. If you want new ones, you need to install a plugin called Regenerate Thumbnails.

And it’s on the repository. It was created by Alex Mills, who’s no longer with us. But it still has a million active installations.

So you’re going to activate and now you’re going to use it in a couple of different ways. You can go to ‘Tools’ and ‘Regenerate Thumbnails’, it’ll just regenerate all of them, you’ll actually go into the ‘Media Library’, and click Regenerate Thumbnails right here and do just one image.

So let’s do that first. So it tells me that it’s not going to do these four that already exists, but it’s going to create these or no, it’s not going to create these new ones, because it would be larger than the original.

So let’s hit ‘regenerate thumbnails’. And it made one new one topher800. And now we can come over here and there it is 800 by 600.

Let me show you what it looks like if you do all of them. Here you have the option to delete thumbnail files for old unregistered sizes.

So if I went into my code and deleted my 800 add_image_size and rerun it, it would delete all those images which is kind of handy.

So I went to regenerate for all five…and there we go. And now you can see there’s an 800 for this one.

There’s an 800 for this one, etc. Now you have new images that you can use in your template tags.

Next week I’ll show you how to be able to access them in your WordPress menus.

I hope you find it useful.

Workshop Details