使用Woocommerce和我的Storefront子主题,我试图避免以下事实:单击单个产品图像时,它会打开一个包含完整尺寸图像的新页面。
我希望图片不可点击,因此如果用户单击产品页面中的图片,则不会发生任何事情。
在我的儿童主题function.php中,以下代码阻止缩放和打开灯箱中的图像,但我想完全停用该链接。
add_action( 'after_setup_theme', 'remove_hemen_theme_support', 100 );
function remove_hemen_theme_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
remove_theme_support( 'wc-product-gallery-lightbox' );
}
我该如何实现?
答案 0 :(得分:3)
添加此过滤器,它将删除您的超链接
function e12_remove_product_image_link( $html, $post_id ) {
return preg_replace( "!<(a|/a).*?>!", '', $html );
}
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'e12_remove_product_image_link', 10, 2 );
答案 1 :(得分:1)
您可以覆盖主题中的模板woocommerce / single-product / product-thumbnails.php。
它运行:
apply_filters(
'woocommerce_single_product_image_thumbnail_html',
sprintf(
'<a href="%s" class="%s" title="%s" data-rel="prettyPhoto[product-gallery]">%s</a>',
esc_url( $props['url'] ),
esc_attr( $image_class ),
esc_attr( $props['caption'] ),
wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ), 0, $props )
),
$attachment_id,
$post->ID,
esc_attr( $image_class )
);
答案 2 :(得分:0)
我是如何用相同的主题做到这一点的。
我创建了一个简单的插件(但是您可以使用functions.php),其中包含我需要重写主题的函数,并且在我的代码里面:
add_action( 'wp', 'ts_remove_zoom_lightbox_gallery_support', 99 );
function ts_remove_zoom_lightbox_gallery_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
remove_theme_support( 'wc-product-gallery-lightbox' );
}
我们的功能之间的区别在于,我使用的是“ wp”而不是“ after_setup_theme”。
尝试一下,让我知道是否可行。