Make WordPress Core


Ignore:
Timestamp:
03/08/2009 05:42:17 AM (16 years ago)
Author:
azaozz
Message:

Add alt text and filter to wp_get_attachment_image(), props Sam_a, fixes #8732

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/media.php

    r10682 r10744  
    515515
    516516/**
    517  * Retrieve img HTML content for an image to represent an attachment.
    518  *
    519  * @see wp_get_attachment_image_src() Returns img HTML element based on array.
     517 * Get an HTML img element representing an image attachment
     518 *
     519 * @uses apply_filters() Calls 'wp_get_attachment_image_attributes' hook on attributes array
     520 * @uses wp_get_attachment_image_src() Gets attachment file URL and dimensions
    520521 * @since 2.5.0
    521522 *
     
    534535        if ( is_array($size) )
    535536            $size = join('x', $size);
    536         $html = '<img src="'.attribute_escape($src).'" '.$hwstring.'class="attachment-'.attribute_escape($size).'" alt="" />';
     537        $attachment =& get_post($attachment_id);
     538        $attr = array(
     539            'src'   => $src,
     540            'class' => "attachment-$size",
     541            'alt'   => trim(strip_tags( $attachment->post_excerpt )),
     542            'title' => trim(strip_tags( $attachment->post_title )),
     543            );
     544        $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment );
     545        $attr = array_map( 'attribute_escape', $attr );
     546        $html = rtrim("<img $hwstring");
     547        foreach ( $attr as $name => $value ) {
     548            $html .= " $name=" . '"' . $value . '"';
     549        }
     550        $html .= ' />';
    537551    }
    538552
Note: See TracChangeset for help on using the changeset viewer.