WordPress Gallery Thumbnail Fix

This was an issue I noticed on a theme I use on another site. It’s also not the first time I’ve deal with it, so I thought I’d share the fix for those of you struggling with it. That issue being that WordPress galleries won’t use the actual thumbnail image in the gallery even though you’ve selected it.

The interesting thing with this issue is that visually you’ll see the images in the WordPress gallery at the thumbnail size. So, you may have this issue and not be aware of it.

What I did was to view the image properties in Chrome. I have an extension installed for just that. If you have Firefox then it’s a native feature.

Anyway, when I viewed the image properties I could see the WordPress gallery serving my medium image size, despite having thumbnail set in the gallery, and resizing it with CSS to my thumbnail size.

According to WordPress, thumbnail is the default size and should be used when no size is specified. Meaning, if you view the Text version of your article to see the gallery shortcode, and see no size attribute specified, that it should use the value thumbnail when shown on the site.

The problem is that isn’t always the case and I’m honestly not sure why. However, I have learned how to fix it and it’s really simple.

Fixing WordPress’ Gallery Thumbnail Image Size

Ideally you’ll have a child theme for this. In either case, below is the code you want.

add_filter('shortcode_atts_gallery','my_gallery_atts', 99, 3);

function my_gallery_atts($output, $pairs, $atts) {
	if(!$atts['size']) $output['size'] = 'thumbnail';
	else $output['size'] = $atts['size'];

	return $output;

So, what this does it checks the gallery shortcode, and if it doesn’t see a size attribute specified then it will specifically set it to thumbnail.

This gets around any issues with relying on WordPress to properly set a default value when rendered and should work for everyone.

Please Rate this Article

Please take a second to rate this. It helps us deliver to you the stuff you enjoy.

Author: Thor

I started blogging in 2009 for my wargaming blog. I've been blogging ever since. I even created a niche site about miniature storage of all things.

I have created a free 40K roster builder. I've also set up, maintain, and run my wife's site where she sells the Makeup Eraser.

I'm also a PHP programmer for a local web hosting company where I develop WordPress plugins.

Leave a Reply!

Note: You can comment as a guest by clicking the field indicated Name and checking off “

Leave a Reply


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Notify of