I did this using jQuery to remove the link for the user. For the spiders, I set it to link=”file” so that the spiders don’t crawl to a useless page.
I don’t like modifying the core files since it’ll break again every time you upgrade your WP installation. Hope this helps.
$(document).ready(function(){
// Remove link from gallery images
$(".gallery-icon a").each(function () {
$(this).replaceWith($(this.childNodes));
});
});