Galería Happyfiles con FancyBox text

                  <?php 
// Usage [hf-fb-gallery id="12"]
// Requires HappyFiles.io plugin. ID = Happyfiles folder ID
add_shortcode( 'hf-fb-gallery' , 'happyfiles_fancybox_gallery' );

function happyfiles_fancybox_gallery($attr){
    $args = shortcode_atts( array(
            'id' => '0'
        ), $attr );
    $id = $args['id'];
    $query_images_args = array(
    'post_type' => 'attachment',
    'post_mime_type' =>'image',
    'post_status' => 'inherit',
    'posts_per_page' => -1,
    'tax_query' => array(
        array(
            'taxonomy' => 'happyfiles_category',
            'field'    => 'ID',
            'terms'    => $id,
        ),
    ),
);
$query_images = new WP_Query( $query_images_args );
$images = array();

    $buffer = '
    <script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui@4.0/dist/fancybox.umd.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" />
 
    <div class="gallery grid-4-3-2">
    ';
    foreach ( $query_images->posts as $image) {
    $img = wp_get_attachment_image_url( $image->ID, "full");
    $img_thumb = wp_get_attachment_image_url( $image->ID, "thumbnail");
    $caption = wp_get_attachment_caption($image->ID);
    $buffer .='<a data-fancybox="'.$id.'" data-src="'.$img.'" data-caption="'.$caption.'">';
	$buffer .='<img loading="lazy" src="'.$img_thumb.'" style="max-width:100%;height:auto;" />';
    $buffer .='</a>';
    }
    $buffer .='</div>';
    wp_reset_postdata();
    return $buffer;
}