Change image thumbnail size in WordPress gallery

Change image thumbnail size in WordPress gallery

WordPress offers very useful built in functionality where you can specify image size for galleries within dashboard. But, what if you want to automatically change image size for all galleries? Here is a neat solution with just couple of lines of PHP code.

Understanding WordPress native gallery system

First, let’s take a look at how WordPress gallery system works. By default, WordPress provides you with 3 basic image sizes you can modify in Media Settings. See an example below:

meks_wp_media_settings

Whilst creating a gallery inside your post/page content, you are able to choose image size you want to use for particular gallery. Four sizes are available by default: Thumbnail, Medium, Large and Full (originally uploaded image).

meks_wp_edit_gallery

All right, so far so good! But, imagine that you have just switched to a brand new WordPress theme which has a totaly different styling. Obviously, you don’t want to go back to each gallery and change appropriate size settings one by one. Here’s a solution.

Introducing shortcode_atts_gallery filter

This simple snippet will do the trick. Just take a look at the example below:

And here is one addition to previous snippet. For example, if you want to use specific image size depending on the number of columns set for a particular gallery. This may be quite useful so the images use appropriate sizes ( i.e. instead of using big images if you have thumbnail styled gallery).

Ok, that’s it! Just add this snippet to your theme functions.php file and modify snippet for your needs.

Live example?

We have used this approach inside our Throne WordPress Theme so feel free to take a look and see how galleries with different number of columns use different image sizes.

Bojan Petrovic

Co-founder and WordPress developer at Meks. He has been involved in the business since 2009. creating themes, plugins and services on top of WordPress, continuously aiming to choose best approaches and work smarter, not harder.

9 comments

Leave a comment

Leave a Reply

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