• i have this code

        foreach ($attachments as $id => $attachment) {
            // Fetch the thumbnail (or full image, it's up to you)
    //      $img = wp_get_attachment_image_src($id, 'medium');
    //      $img = wp_get_attachment_image_src($id, 'my-custom-image-size');
            $img = wp_get_attachment_image_src($id, 'full');
    
            $output .= "<li class=\"grid-item\"><a href=\"{$img[0]}\" data-lightbox=\"example-set\">\n";
            $output .= "<img src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"photograph in gallery\" />\n";
            $output .= "</a></li>\n";
        }

    how can i change “photograph in gallery” (the alt) to the real alt of the image?

Viewing 1 replies (of 1 total)
  • Joey

    (@leglesslizard)

    Hi,

    Try:

    $img    = wp_get_attachment_image( $id, 'full' );
    $img_url = wp_get_attachment_image_url( $id, 'full' );
    
    $output .= '<li class="grid-item"><a href="' . $img_url . '" data-lightbox="example-set">';
    $output .= $img;
    $output .= '</a></li>';

    I have replaced the function. “wp_get_attachment_image()” will return the html for displaying an image with all your pre-defined settings.

    Hope that helps,
    Joey

Viewing 1 replies (of 1 total)
  • The topic ‘Get Thumbnail Alt for gallery’ is closed to new replies.