I"m just ACF, and i've created and Image as an ID. The code is all working perfectly apart from the alt tag isn't being outputted.

What have I got wrong?

$attachment_id_desktop = get_sub_field('image');
$size_desktop = "column-size"; // (thumbnail, medium, large, full or custom size)
$image_desktop = wp_get_attachment_image_src( $attachment_id_desktop, $size_desktop );
$alt_desktop = get_post_meta($attachment_id_desktop , '_wp_attachment_image_alt', true);

<img class="img-fluid desktop" alt="" src="<?php echo $image_desktop[0]; ?>" alt="<?php echo $alt_desktop; ?>"/>
  • Not a perfect solution, but I don't understand why your code doesn't work. May be use the array instead of the image ID and then use the already populated attributes of the array returned. :/
    – Elex
    Commented Apr 2, 2020 at 18:23
  • Odd one isn't it, I would usually use an Array, but I'm setting the size of an image. Can you do that with an array?
    – M.T
    Commented Apr 2, 2020 at 18:33

1 Answer 1


Basically, I was being totally stupid and had two alt tags that's why it didn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.