Make WordPress Core

Opened 7 years ago

Last modified 4 years ago

#40692 new defect (bug)

Filter default image size in gallery

Reported by: catapult_themes's profile Catapult_Themes Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8
Component: Gallery Keywords:
Focuses: ui Cc:


Using the media_view_settings filter, I can specify default link and column settings for new galleries but the size parameter is not filterable. For example:

function me_filter_gallery_settings( $settings ) {
	// This will successfully set the default number of columns to 5
	$settings['galleryDefaults']['columns'] = 5;
	// This does nothing
	$settings['galleryDefaults']['size'] = 'large';
	return $settings;
add_filter( 'media_view_settings', 'me_filter_gallery_settings' );

I know that it’s possible to override these defaults when outputting the gallery via the gallery_shortcode. However, this may be confusing to the user who would expect to see the same value for the image size appear when the gallery is generated on the front end as they have seen in the admin. To clarify: at the moment, I can set a default size for gallery images to ‘medium’, for example, although in the Gallery Settings panel in the page editor, the size will still display as ‘Thumbnail’. Indeed, the user could change the value of the size field without actually affecting the image size on the front end.

In wp-includes/media-template.php replace lines 775 - 779 with:

foreach ( $size_names as $size => $label ) : ?>
	<option value="<?php echo esc_attr( $size ); ?>" <#
		if ( '<?php echo $size ?>' == ) { #>selected="selected"<# }
		<?php echo esc_html( $label ); ?>
<?php endforeach; ?>

This will allow:

function me_filter_gallery_settings( $settings ) {
	$settings['galleryDefaults']['size'] = 'large';
	return $settings;
add_filter( 'media_view_settings', 'me_filter_gallery_settings' );

Thereby allowing plugin and theme developers to set a default value for the image size in galleries.

Attachments (1)

40692.diff (605 bytes) - added by palmiak 7 years ago.

Download all attachments as: .zip

Change History (8)

7 years ago

#1 @palmiak
7 years ago

I've tested the solution proposed by Catapult_themes and created diff file.


#2 @chrisvanpatten
7 years ago

Looks like a duplicate of #35654, although this ticket has a patch and #35654 does not. Someone more well-versed in Trac gardening probably knows what to do in this case (move the patch and close this, or close the original?)

#3 @stephaneguigne
7 years ago

In the meantime, if you want a workaround this issue, you can select the correct image size in the dropdown when the template is generated in order to match your default gallery settings.

#4 @nicmare
7 years ago

please fix that. thanks.

#5 @cezariuszmarek
6 years ago

  • Type changed from enhancement to defect (bug)

In my opinion it's a bug. I expect the "size" default to work the same as the "columns" or "link" ones.

#6 @cezariuszmarek
6 years ago

#35654 was marked as a duplicate.

#7 @Jorim
4 years ago

Is there any change this is going to be added in a future version? Especially because the fix is already provided and testing is done? And I can also add that this fix is working. I'm re-implementing it after every new version...


Note: See TracTickets for help on using tickets.