To change the default size of images displayed in the WordPress media gallery, you can add the following code to your theme’s functions.php file:
function my_gallery_default_type_set_link( $settings ) {
$settings['galleryDefaults']['link'] = 'file';
$settings['galleryDefaults']['size'] = 'thumbnail'; //replace 'thumbnail' with your desired image size name
return $settings;
}
add_filter( 'media_view_settings', 'my_gallery_default_type_set_link');
This code sets the default image size for the gallery to ‘thumbnail’, but you can replace ‘thumbnail’ with any registered image size name that you want to use.
If you have optimized image sizes and webp enabled, you can also create your own custom image size using the add_image_size()
function and use that size in the code above. For example:
function my_custom_image_sizes() {
add_image_size( 'custom-size', 800, 600 ); //set the desired dimensions for your custom image size
}
add_action( 'after_setup_theme', 'my_custom_image_sizes' );
Then, replace ‘thumbnail’ with ‘custom-size’ in the code above to set your custom size as the default for the gallery.
I hope this helps! Let me know if you have any further questions.