Unwanted empty space under each row of gallery images can be really annoying, if you love pixel-perfect layouts, you may have noticed this issue while adding WordPress Image Galleries.
I’ve tested few different fixes and finally I’ve found working code snipped which is removing unwanted br[clear]
tags from WordPress image gallery output.
tags from WordPress image gallery output.
[clear]
Below code snippet will help you to remove unwanted br tags from WordPress image galleries. Add this snippet in to functions.php file in your theme folder.
[clear]
add_filter( 'the_content', 'remove_br_gallery', 11, 2);
function remove_br_gallery($output) {
return preg_replace('/<br style=(.*)>/mi','',$output);
}
[clear]
There is also a bit of css which can be added to style.css in your theme folder to make the fix even better.
.gallery br {
display:none;
}
.gallery:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
[clear]





