Change Default Number of Gallery Columns

To change the default number of gallery columns in WordPress, use the snippet below:

function wpkb_theme_gallery_defaults( $settings ) {
    $settings['galleryDefaults']['columns'] = 2;
    return $settings;
}

add_filter( 'media_view_settings', 'wpkb_theme_gallery_defaults' );