• I am using Twenty-Twenty theme with the very basic, included Gallery options.

    I have used the following code in functions.php to change the link and number of columns (so I don’t have to change them every time I create a gallery):

    function theme_gallery_defaults( $settings ) {
        $settings['galleryDefaults']['columns'] = 4;
        $settings['galleryDefaults']['link'] = 'file';
        return $settings;
    }
    add_filter( 'media_view_settings', 'theme_gallery_defaults' );

    Occasionally I would like to create galleries that are three columns wide instead of four, but the default thumbnail size is too small and leaves a lot of space. I’d like to use a larger thumbnail for a three-column gallery.

    I have added the code in functions to create new image sizes and it works! My new image size even shows up in the gallery interface, and I can choose it and it displays properly.

    I have discovered that this particular gallery smallenizes the thumbnail to fit (for instance, if I use five columns, it resizes the thumbnails to 100×100 instead of 150×150). So I figured if I used my new image size as the default, it wouldn’t matter. And it doesn’t! But I have to change it every time. I’d like to have it automatically selected, by default. I tried adding the following to the above code:
    $settings['galleryDefaults']['size'] = 'three-wide';
    But that didn’t work.

    So now I’m stuck!

    How can I have my new image size selected by default in the gallery interface?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter SaladGoat

    (@saladgoat)

    I have found this article with a code that looks like it should do what I want, but it appears to do nothing.
    https://amethystwebsitedesign.com/how-to-get-larger-images-in-a-wordpress-gallery/#method2
    It’s also almost nine years old, so maybe WordPress has changed some stuff since then?

    Thread Starter SaladGoat

    (@saladgoat)

    I feel like I’m getting close….
    I did a search through all the WordPress files and found this code in wp-includes/media-template.php:

    <span class="setting size">
    			<label for="gallery-settings-size" class="name"><?php _e( 'Size' ); ?></label>
    			<select id="gallery-settings-size" class="size" name="size"
    				data-setting="size"
    				<# if ( data.userSettings ) { #>
    					data-user-setting="imgsize"
    				<# } #>
    				>
    				<?php
    				/** This filter is documented in wp-admin/includes/media.php */
    				$size_names = apply_filters(
    					'image_size_names_choose',
    					array(
    						'thumbnail' => __( 'Thumbnail' ),
    						'medium'    => __( 'Medium' ),
    						'large'     => __( 'Large' ),
    						'full'      => __( 'Full Size' ),
    					)
    				);
    
    				foreach ( $size_names as $size => $label ) :
    					?>
    					<option value="<?php echo esc_attr( $size ); ?>">
    						<?php echo esc_html( $label ); ?>
    					</option>
    				<?php endforeach; ?>
    			</select>
    		</span>

    I added my custom size at the top of the array and now my Gallery shows my custom size as the default, as well as showing another of my custom sizes at the bottom of the list (despite not being included here).

    Obviously this is not the ideal solution, as this change will be erased on the next WordPress update. So I need some help to turn this into something I can add in my child’s functions.php to make it a permanent fix.

    This code begins at line 876, but the full Gallery code begins at line 831.

    Can you please help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to change default gallery image size’ is closed to new replies.