How To Remove WooCommerce Product Image Link

WooCommerce automatically wraps your main product image in an <a> tag. It either links to the lightbox, or if you've disabled product image zoom it leaves a link to the image.

screenshot of example woocommerce product with arrow pointing to product image

If you want to get rid of that link, there's no easy setting (as of WooCommerce 5.4.1) to disable it.

To remove the link around the WooCommerce product image, add the following code to your functions.php:

add_filter( 'woocommerce_single_product_image_thumbnail_html', 'custom_remove_product_link' );
function custom_remove_product_link( $html ) {
  return strip_tags( $html, '<div><img>' );
}

This takes the raw HTML and strips everything other than the div and image.

The code you're hooking into is at /templates/single-product/product-image.php.

The HTML is actually built by wc_get_gallery_image_html() in /includes/wc-template-functions.php, but if you pull that up, you'll see there are no filters to change how the HTML is built.

Mike Haydon

Thanks for checking out my WordPress and coding tutorials. If you've found these tutorials useful, why not consider supporting my work?

Buy me a coffee

1 thought on “How To Remove WooCommerce Product Image Link”

Leave a Comment