How to change the target size of images clicked on in WordPress standard gallery

I came across a solution for your functions.php from the following site that looks like it will do the trick. More detail on the implementation here:

Snippet below:

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, 'galleryimage' );
    $new_content = preg_replace('/href=\'(.*?)\"https://wordpress.stackexchange.com/", 'href=\'' . $image[0] . '\'', $content );
    return $new_content;
} else {
    return $content;
}
}

add_filter('wp_get_attachment_link', 'oikos_get_attachment_link_filter', 10, 4);