一見、意味を測りかねる、remove_filter()、関数内の、add_filter() ちゃんと意味があるんですね。
function filter_gallery_shortcode_output_29832( $gallery, $attr ) { remove_filter( 'post_gallery', __FUNCTION__, 10, 2 ); $gallery= gallery_shortcode( $attr ); add_filter( 'post_gallery', __FUNCTION__, 10, 2 ); // Change the output // $gallery= ... return $gallery; } add_filter( 'post_gallery', 'filter_gallery_shortcode_output_29832', 10, 2 );