Linking images in WordPress Paginated Post

_wp_link_page() returns a HTML string and not just the URL address of the link. So, if the link’s URL address is http://example.com/blah/2/, then _wp_link_page() would return:

<a href="http://example.com/blah/2/">

..i.e. it returns the opening a tag for that link.

So replace the following:

$content = preg_replace('/(<img(.+?)\/>)/i','<a href="'.$link.'">$1</a>', $content);

..with this:

$content = preg_replace('/(<img(.+?)\/>)/i', $link . '$1</a>', $content);