admin管理员组

文章数量:1389674

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; ?>"/>

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; ?>"/>
Share Improve this question asked Apr 2, 2020 at 18:15 M.TM.T 351 silver badge5 bronze badges 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 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
Add a comment  | 

1 Answer 1

Reset to default 1

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

本文标签: advanced custom fieldsACF Image IDecho the alt tag