You need to echo
your wp_get_attachment_image
, BUT since this function returns a HTML object in the form of,
<img src="https://wordpress.stackexchange.com/questions/67508/path/to/image.jpg"/>
It’s not going to work because you are are trying to return this function withing the href
attribute of an anchor <a>
This is wrong,
<a href="https://wordpress.stackexchange.com/questions/67508/<?= wp_get_attachment_image( $attachment->ID,"blog-thumb'); ?>"></a>
This is right,
<a href="https://wordpress.stackexchange.com/questions/67508/<?php echo wp_get_attachment_image_src( $attachment[0]->ID,"blog-thumb'); ?>">
<?php echo wp_get_attachment_image( $attachment->ID, 'blog-thumb'); ?>
</a>
So all in all something like this which is a little neater despite that we are still mixing two image functions that could be condensed down into just using wp_get_attachment_image_src
however the following will still work,
foreach ($attachments as $attachment) {
$src = wp_get_attachment_image_src( $attachment[0]->ID );
$html="<a href="".$src.'">';
$html .= wp_get_attachment_image( $attachment->ID, 'blog-thumb') .'</a>';
echo $html;
}