In WordPress, images are automatically re-saved in different sizes like creating a thumbnail. But what happens if you want to use your own image? or want a different size?

WordPress default image sizes

The standard WordPress image sizes are:

  • Thumbnail (no more than 150px wide)
  • Medium (no more than 300px)
  • Large

These basically are crops and the size (width) is based on the aspect ratio. So you can't always guarantee that your thumbnail will be exactly 150px x 150px.

How to get your image thumbnail

In my plugins, I use the standard WordPress image sizes like this:

Get the standard thumbnail
get_the_post_thumbnail($id, 'thumbnail', array('class' => 'dsimage'))
Get a custom image of 200×200 px
But you can tell WordPress to give you your own image size like this
get_the_post_thumbnail($id, array(200,200), array('class' => 'dsimage'))

Note: each image will also get a custom class added called dsimage - this means you can style it.

Tags: aspect ratio, custom images, images, thumbnail

Read more from my blog for an introduction and quick tips on developing in Hugo or UCTD.

Meet the author

Photo for Damien Saunders
Damien Saunders
An experienced management consultant and business leader interested in digital transformation, product centred design and scaled agile. If I'm not writing about living with UCTD (an autoimmune disease), I'm probably listening to music, reading a book or learning more about wine.