diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
index 5796caf28c..69079a8023 100644
--- a/src/wp-includes/media.php
+++ b/src/wp-includes/media.php
@@ -996,8 +996,12 @@ function gallery_shortcode( $attr ) {
$output .= '
';
}
+ if ( $columns > 0 && $i % $columns !== 0 ) {
+ $output .= "
+
";
+ }
+
$output .= "
-
\n";
return $output;