I'm trying to remove the link on the featured image when I add a new product in Woocommerce. I did it in the previous version but since updating I can't seem to find how/where I edited it. Trying to look through some files to no avail. Any help?
On WordPress.com it's not possible to add a link directly to a featured image, but featured images should by default link to the post where they appear in the main feed of the site. If I view your site's feed at https://toosanguine.wordpress.com/blog/ every featured image is linking to the post, same as the post title.
Click on the settings icon at the top of the page. By default, you will start in the Block section. Click on the Document section. Scroll down until you have found the Featured Image from URL option.
I originally used css: pointer-events:none;
On the link class (I think I used .zoom img) however I needed to use the image for a jQuery zoom so after hours of searching I found this solution, just add this to your functions.php and it will sort you out.
/**
* Remove link wrapping main product image in single product view.
* @param $html
* @param $post_id
* @return string
*/
function custom_unlink_single_product_image( $html, $post_id ) {
return get_the_post_thumbnail( $post_id, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) );
}
add_filter('woocommerce_single_product_image_html', 'custom_unlink_single_product_image', 10, 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With