WordPress.org

Make WordPress Core

Ticket #18178: media.php.galleryshortcodelinknone.diff

File media.php.galleryshortcodelinknone.diff, 1.4 KB (added by chipbennett, 3 years ago)

Add link="none" support to [gallery] shortcode, to enable output of flat/unlinked images

  • media.php

     
    850850 
    851851        $i = 0; 
    852852        foreach ( $attachments as $id => $attachment ) { 
    853                 $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); 
     853                /* 
     854                 * Output image link. By default, image links to 
     855                 * attachment page. If link="file" is passed to 
     856                 * the shortcode, the image links directly to  
     857                 * the file. 
     858                 */  
     859                $image_link = isset( $attr['link'] ) && 'file' == $attr['link'] ? wp_get_attachment_link( $id, $size, false, false ) : wp_get_attachment_link( $id, $size, true, false ); 
     860                /* 
     861                 * Output flat image. By default, image links to 
     862                 * attachment page. If link="none" is passed to 
     863                 * the shortcode, a flat (unlinked) image is 
     864                 * output. 
     865                 */ 
     866                $flat_image = ( isset( $attr['link'] ) && 'none' == $attr['link'] ? wp_get_attachment_image( $id, $size, false ) : false ); 
     867                // Determine whether to output a linked or flat image 
     868                $image_output = ( $flat_image ? $flat_image : $image_link ); 
    854869 
    855870                $output .= "<{$itemtag} class='gallery-item'>"; 
    856871                $output .= " 
    857872                        <{$icontag} class='gallery-icon'> 
    858                                 $link 
     873                                $image_output 
    859874                        </{$icontag}>"; 
    860875                if ( $captiontag && trim($attachment->post_excerpt) ) { 
    861876                        $output .= "