How can I modify this PHP


hi guys first post here all help much appreciated, I have this bit of PHP on my Wordpress site currently, I was wondering if it would be possible to alter this php in such a way it only redirects when an image is clicked instead of everything with a link embedded e.g product titles and headings. many thanks Matt.

add_action('template_redirect', 'redirect_external_products');
function redirect_external_products() {
    global $post;
    if (is_singular( 'product' ) &&
        ! empty( $post ) &&
        ($product = wc_get_product($post)) &&
         $product->is_type('external' )) {

        wp_redirect( $product->get_product_url() );

then you should make an image with a unique link that has a special parameter that you can rely on in your script with if(...)