1

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?

<?php 
$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; ?>"/>
2
  • 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
    Apr 2 '20 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
    Apr 2 '20 at 18:33
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, privacy policy and cookie policy

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