• Resolved jamessuske1985

    (@jamessuske1985)


    I have this custom hook for WordPress Galleries:

    function custom_gallery_output( $output, $atts, $instance ) {
    global $post;

    // Get the gallery image IDs
    if ( isset( $atts['ids'] ) ) {
        $ids = explode( ',', $atts['ids'] );
    } else {
        $ids = [];
    }
    
    if ( empty( $ids ) ) {
        return $output;
    }
    
    $gallery_id = 'gallery-' . $post->ID;
    
    $output = '<div class="custom-gallery">';
    
    foreach ( $ids as $id ) {
        $image_url = wp_get_attachment_image_url( $id, 'full' );
    
        $output .= '<figure class="gallery-item">';
        $output .= '<div class="gallery-icon landscape">';
        $output .= '<a href="' . esc_url( $image_url ) . '" class="gallery" data-lightbox="gallery" style="display:block; background-image:url(' . esc_url( $image_url ) . '); background-size:cover; background-position:center; width:100%; height:300px;"></a>';
        $output .= '</div></figure>';
    }
    
    $output .= '</div>';
    
    return $output;

    }
    add_filter( ‘post_gallery’, ‘custom_gallery_output’, 10, 3 );

    This works, except it only shows one image, I am trying to create a set via data-lightbox=”gallery” but that did not work. It opens the image I click on in lightbox, but I have to close it and open the next image, Dont know why the arrows dont appear.

Viewing 1 replies (of 1 total)
  • Plugin Author Johannes Kinast

    (@goaroundagain)

    Hi @jamessuske1985,

    You need to change the CSS selector to include your main gallery class .custom-gallery

    Add this to your functions.php:

    add_filter( 'baguettebox_selector', function( $selector ) { return $selector . ',.custom-gallery'; } )

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.