I’ve tested the following and it works for me. This uses the image’s Title for the ‘alt’ text and displays the image’s caption below the image itself.
Use this in content-attachment.php, replacing the current the_content function:
$attachment_id = get_the_ID();
// If this attachment is an Image, show the large size
if ( wp_attachment_is_image( $attachment_id ) ) {
$attachment_image = wp_get_attachment_image($attachment_id, '', '', array('class' => 'post-thumbnail', 'size' => 'large', 'alt' => the_title_attribute(array('post'=>$attachment_id,'echo'=>0)) ) );
echo $attachment_image;
echo '<div class="caption">' . get_the_excerpt() . '</div>';
} else {
// Normal display for other mime types like PDFs
the_content(
sprintf(
wp_kses(
__( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'vanguard-history' ),
array(
'span' => array(
'class' => array(),
),
)
),
wp_kses_post( get_the_title() )
)
);
}