Opened 8 years ago
Last modified 4 years ago
#40692 new defect (bug)
Filter default image size in gallery
Reported by: | Catapult_Themes | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.8 |
Component: | Gallery | Keywords: | |
Focuses: | ui | Cc: |
Description
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 ?>' == wp.media.galleryDefaults.size ) { #>selected="selected"<# } #>> <?php echo esc_html( $label ); ?> </option> <?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)
Change History (8)
#3
@
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.
I've tested the solution proposed by Catapult_themes and created diff file.
#wcpl2017