Thanks to @Hai
Add it to your functions.php and it will use the ‘fancyapps-image’ version of the image wherever WordPress is displaying a link to an attached image. Hope it helps.
function oikos_get_attachment_link_filter( $content, $post_id, $size, $permalink ) {
// Only do this if we're getting the file URL
if (! $permalink) {
// This returns an array of (url, width, height)
$image = wp_get_attachment_image_src( $post_id, 'fancyapps-image' );
$new_content = preg_replace('/href=\'(.*?)\"https://wordpress.stackexchange.com/", 'href=\'' . $image[0] . '\'', $content );
return $new_content;
}
}
add_filter('wp_get_attachment_link', 'oikos_get_attachment_link_filter', 10, 4);
Code from http://oikos.org.uk/2011/09/tech-notes-using-resized-images-in-wordpress-galleries-and-lightboxes/