如何更改目录缩略图,产品缩略图中的元(alt和标题)? - Woocomerce [英] How can i change meta (alt and title) in catalog thumbnail , product thumbnail ? - Woocomerce

查看:175
本文介绍了如何更改目录缩略图,产品缩略图中的元(alt和标题)? - Woocomerce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下, Woocommerce 表示alt使用的图像文件的名称。

By default in Woocommerce for alt used image file's name.

有谁知道如何更改缩略图元(alt和标题)以显示产品名称

Does anyone know how to change thumbnail meta (alt and title) to show Product name?

推荐答案

尝试这样:

add_filter('wp_get_attachment_image_attributes', 'change_attachement_image_attributes', 20, 2);

function change_attachement_image_attributes( $attr, $attachment ){
    // Get post parent
    $parent = get_post_field( 'post_parent', $attachment);

    // Get post type to check if it's product
    $type = get_post_field( 'post_type', $parent);
    if( $type != 'product' ){
        return $attr;
    }

    /// Get title
    $title = get_post_field( 'post_title', $parent);

    $attr['alt'] = $title;
    $attr['title'] = $title;

    return $attr;
}

这篇关于如何更改目录缩略图,产品缩略图中的元(alt和标题)? - Woocomerce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆