image - 检索图像附件的替代文本?
问题描述
我很难弄清楚如何获取附件图像的 alt 属性。我尝试了 8 个代码,但没有一个显示 alt 属性
看起来这个 WP 主题正在使用gallery-metabox插件。
<?php if ( !empty($screenshots) ) { ?>
<div class="screenshotspgcntn col-md-6">
<h4>Images <?php the_title(); ?></h4>
<div class="allphotosgallery clearfix">
<?php if($screenshots) : foreach ($screenshots as $key => $value) :
$image = wp_get_attachment_image_src($value, 'thumbnail');
$url = wp_get_attachment_image_src($value, 'large');
/* I tried all of these: */
$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE);
$image_alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
$image_alt = get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true);
$image_alt = get_post_meta( $image->id, '_wp_attachment_image_alt', true);
$image_alt = $img_meta['alt'] == '' ? $image_title : $img_meta['alt'];
$image_alt = get_post_meta($imgID,'_wp_attachment_image_alt', true);
$image_alt = get_post_meta( $image->id, '_wp_attachment_image_alt', true);
$image_alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
?>
<div class="perfundo">
<a href="#lightbox-image">
<img src="<?php echo $image[0]; ?>" alt="<?php echo $image_alt; ?>">
</a>
<div id="lightbox-image" class="perfundo__overlay fadeIn">
<figure class="perfundo__figure">
<img src="<?php echo $image[0]; ?>">
<div class="perfundo__image" style="width: 800px; padding-top: 66.25%; background-image: url(<?php echo $url[0]; ?>);"></div>
</figure>
<a href="#image-closed" class="perfundo__close perfundo__control">Close</a>
</div>
</div>
<?php endforeach; endif; ?>
</div>
</div>
<?php } ?>
解决方案
推荐阅读
- php - Eloquent - 如何在没有观察者的情况下等到 create() 之后
- php - 网关响应在子目录 wordpress 安装中不起作用
- go - 如何使用 Sarama Go Kafka Consumer 从最新的偏移量中消费
- react-native - “create-react-app my-app”无法识别
- node.js - 如何在 Nestjs 中添加外部/第三方节点模块
- excel - 如何解决 VBA 2013 中的“对象库未注册”错误?
- java - Mongodb java在两个日期字段之间输入日期
- javascript - 使用预签名 URL 从 PUT 到 S3 的 400 错误请求
- postgresql - 特定月份无交易时不打印月份
- php - 如何通过Php在邮递员中发送标题