如何在不实际进入php文件并手动删除类的情况下,从wooccommerce中的图像中删除缩放类?喜欢用钩子吗?
我找到了的过滤器
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_title, $image ), $post->ID );
但我不知道如何推翻这一点?这里的变焦很烦人。
您可以通过过滤器进行调整。对于你在WordPress中看到的任何类型的过滤器,这都是相同的方法,你可以发回你想要使用的值。如果你想阅读更多,我想我写了一篇关于WordPress过滤器的文章。
但为了回答你的问题,你可以做以下操作,这将保持图像链接的完整性,但删除缩放类:
function so_26609604_single_product_image_html( $html, $post_id ){
$image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );
$image_link = wp_get_attachment_url( get_post_thumbnail_id() );
$image = get_the_post_thumbnail( $post_id, 'shop_single', array( 'title' => $image_title ) );
$html = sprintf( '<a href="%s" itemprop="image" class="woocommerce-main-image" title="%s">%s</a>', $image_link, $image_title, $image );
return $html;
}
add_filter( 'woocommerce_single_product_image_html', 'so_26609604_single_product_image_html', 10, 2 );
或者你可以完全删除链接,只显示一张图片:
function so_26609604_single_product_image_html_alt( $html, $post_id ){
$image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );
$image = get_the_post_thumbnail( $post_id, 'shop_single', array( 'title' => $image_title ) );
return $image;
}
add_filter( 'woocommerce_single_product_image_html', 'so_26609604_single_product_image_html_alt', 10, 2 );