This code in your functions.php theme will replace any image with a link to its attachment page with a link to the image itself.