[英]Wordpress Woocommerce alt text in images
I'm building a Woocommerce and I'm having trouble getting the Alt Text displayed in the front-end. 我正在构建Woocommerce,但无法在前端显示替代文本。
The code that I'm working on is this: 我正在处理的代码是这样的:
<?php
if ( has_post_thumbnail() ) {
$image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );
$image_caption = get_post( get_post_thumbnail_id() )->post_excerpt;
$image_alt = esc_attr( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) );
$image_link = wp_get_attachment_url( get_post_thumbnail_id() );
$image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array(
'title' => $image_title,
'alt' => $image_alt
) );
$attachment_count = count( $product->get_gallery_attachment_ids() );
if ( $attachment_count > 0 ) {
$gallery = '[product-gallery]';
} else {
$gallery = '';
}
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<a href="%s" itemprop="image" class="woocommerce-main-image zoom" title="%s" data-rel="prettyPhoto' . $gallery . '">%s</a>', $image_link, $image_caption, $image ), $post->ID );
} else {
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="' . $image_alt . '" />', wc_placeholder_img_src(), __( 'Placeholder', 'woocommerce' ) ), $post->ID );
}
?>
<?php do_action( 'woocommerce_product_thumbnails' ); ?>
The code that is this spitting is: 随地吐痰的代码是:
<a href="https://openwallsg..." itemprop="image" class="woocommerce-main-image zoom" title="" rel="lightbox">
<img width="800" height="800" src="https://openwal..." class="attachment-shop_single wp-post-image" alt="" title="bandages bad food">
</a>
I don't get why alt is still empty? 我不明白为什么alt仍然是空的?
There's an _(underscore) before wp_get_attachment_image, remove that to get "alt" value... wp_get_attachment_image之前有一个_(下划线),将其删除以获取“ alt”值...
Reference: https://codex.wordpress.org/Function_Reference/wp_get_attachment_image 参考: https : //codex.wordpress.org/Function_Reference/wp_get_attachment_image
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.