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
1 Answer
Reset to default 1Basically, 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
版权声明:本文标题:advanced custom fields - ACF Image ID, echo the alt tag 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744605756a2615343.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论