• The wp_get_attachment_image function does not populate the alt attribute for the image tag.

    I would suggest that the image caption (post_excerpt) should be the image’s alt tag content and there should be a title attribute which uses the image title (post_title)?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Taken from the depreceated get_attachment_innerHTML function you could meanwhile add something like

    $attachment_id = (int) $attachment_id;
    if ( !$post = & get_post($attachment_id) )
     return false;
    $title = attribute_escape($post->post_title);
    $alt =  attribute_escape($post->post_content);
    ...
    $html = '<img src="'.attribute_escape($src).'" '.$hwstring.'class="attachment-'.attribute_escape($size).'" title="'.attribute_escape($title).'" alt="'.attribute_escape($alt).'" />';

    to the wp_get_attachment_image function. Works well for me but’s a dirty hack and this options schould be implemented in the core of future versions…

    that works pretty well boquiabierto, except that in the Media editor, the field that is listed as “will be used for alt text” doesn’t correspond to post_content. using post_excerpt works a treat though.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_get_attachment_image – alt and title attributes missing’ is closed to new replies.