Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Ben Anggoro
Ben Anggoro
36,161 Points

How to get a uniformed gallery thumbnail size when using WordPress Gallery Shortcode?

Hello everyone,

Hoping can get some help here... again. I would like to change the default gallery thumbnail size when using WordPress Gallery shortcode. The default 150 x 150 doesn't really work with the setting and I would like to have it 320 x 180.

So I add image size on the functions.php, but then got stuck because then the thumbnails come up in different sizes, all having 180 height but the width are varies. I've tried to do hard-crop but not working either.

Then I found this image resizer add-on BFI Thumb which works great, but I don't know how to use it with the gallery shortcode.

To get the custom default gallery thumbnail size, I am using this snippet :

function mytheme_gallery_atts( $out, $pairs, $atts ) {
    $atts = shortcode_atts( array(
        'columns' => '3',
        'size' => 'custom-size'
         ), $atts );
    $out['columns'] = $atts['columns'];
    $out['size'] = $atts['size'];
    return $out;
}
add_filter( 'shortcode_atts_gallery', 'mytheme_gallery_atts', 10, 3 );

I tried to change the array parameters on the 'size' with bfithumb like so

'size' => array( 320,180, 'bfi_thumb' => true)

Which Im pretty sure it's not the right way of doing it as I wasn't sure what I was doing :D But the thing is, it actually works! Just that I get this warning:

Notice: Array to string conversion in /.../media.php on line 1036

So maybe I almost get this right -cause the images were resized as expected, but how can I do this properly?

Thanks in advance, appreciate any advice in advance. Ben

Btw Zac, would you please do a course on this gallery shortcode? Cause seriously the built-in is not that awesome and most of the time we need to customize it for clients (who mostly don't know how to use it anyway). And maybe in a way so we don't have to use plugin or jetpack? Jetpack is too much sometime for what we need i think.

Thanks