Allowing For Custom Images Sizes with WordPress's Gallery Shortcode Allowing For Custom Images Sizes with WordPress's Gallery Shortcode wordpress wordpress

Allowing For Custom Images Sizes with WordPress's Gallery Shortcode


I know this is late, but I found this question trying to accomplish the same thing.

The Gallery does not have any built-in filters to allow this, so I developed a solution that works below.

In your theme's functions.php file, add the following lines of code:

remove_shortcode('gallery');add_shortcode('gallery', 'custom_size_gallery');function custom_size_gallery($attr) {    // Change size here - medium, large, full    $attr['size'] = 'medium';    return gallery_shortcode($attr);}

This will interrupt the normal gallery call, revise the size being used, and then call the built-in WordPress gallery.


Wordpress crunch the images in several size when you upload them. So you can not get your given size image unless you set it to the admin panel before uploading the image.But you can add additional image size:

add_image_size( 'sidebar-thumb', 120, 120, true ); // Hard Crop Modeadd_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop Modeadd_image_size( 'singlepost-thumb', 590, 9999 ); // Unlimited Height Mode

More about add_image_size() on Codex