Adding a css class to the gallery

If you look at the gallery shortcode you will see that you are using the wrong filter. With post_gallery you can override the complete html of the shortcode. Your code performs a str_replace on an empty string, resulting in an empty return and subsequently the generation of the default gallery html.

Further on there is a filter called gallery_style which is meant to filter the gallery styles, but since the opening div is included you can also use to modify the classes.

tech