Meks
Do you know you can try any of our premium WordPress themes for free?Show me the themes
Change image thumbnail size in WordPress gallery

Change image thumbnail size in WordPress gallery

79Shares

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

Top WP Hosting recommended by Meks

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.

79Shares
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.

Try theme now for free!
  • Access to a copy of the demo website
  • Full access to the theme options
  • No credit card required

* We will send you an occasional newsletter with special offers, news & theme updates but you can unsubscribe at any time.

Meks