Resizing custom images using Shortcode in the WordPress Gallery

WordPress 2.5 and later has a built-in Gallery feature that lets you add a gallery of images to a post or page on your WordPress blog. (Link: http://codex.wordpress.org/Gallery_Shortcode )

You can use the size option to specify the size of the sketch you want to display. Valid values โ€‹โ€‹include Thumbnail, Medium, Large, and Full. The default is thumbnail. Image sizes for thumbnails, medium, and large can be configured in the WordPress admin panel.

T. [gallery size="medium"]

My question is . I am trying to hack the [gallery] shortcode to allow custom sizes during input - without trying to do this through the admin panel. I would like to use something like [gallery size="145x160"] .

Instead, download the bloated plugin, I would prefer to work with what is already there, and I'm not sure where I need to go to my file structure in order to make changes. I am familiar with PHP, but I am afraid that I will make changes, and then when I update future versions of WP, it will overwrite what I set in motion.
Can anyone help me with this?

Many thanks!

+7
php wordpress image-gallery gallery shortcode
source share
2 answers

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

There are no built-in filters in the gallery, so I developed a solution that works below.

In your theme 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 regular gallery call, revise the size used and then call the WordPress built-in gallery.

+9
source share

Wordpress compresses images in several sizes when they are downloaded. Thus, you cannot get your image size unless you install it on the admin panel before uploading the image. But you can add an extra image size:

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

Learn more about add_image_size () on Codex

0
source share

All Articles