【发布时间】:2022-11-15 06:52:28
【问题描述】:
需要防止产品页面的主图延迟加载。
主要产品图片加载在“woocommerce/single-product/product-image.php”中
它使用: wp_get_attachment_image( $attachment_id, $size, $icon, $attr );获取图像。
在上面的函数内部,有:
// Add `loading` attribute.
if ( wp_lazy_loading_enabled( 'img', 'wp_get_attachment_image' ) ) {
$default_attr['loading'] = wp_get_loading_attr_default( 'wp_get_attachment_image' );
}
$attr = wp_parse_args( $attr, $default_attr );
// If the default value of `lazy` for the `loading` attribute is overridden
// to omit the attribute for this image, ensure it is not included.
if ( array_key_exists( 'loading', $attr ) && ! $attr['loading'] ) {
unset( $attr['loading'] );
}
很明显,可以不延迟加载它,但我只是不完全明白我怎么能做到这一点?
【问题讨论】:
标签: php wordpress woocommerce