Unable to Find Space in Custom Function

Ok, well it turns out it has more to do with WordPress then we realised. The wp_link_pages function, in which the hook being used in the question resides, is the culprit rather than anything you’ve done. If you want to have a look, the function is in the post-template.php file inside the wp-includes directory.

The ‘offending’ code is in the loop that outputs the numbers (line 651 in WP3.3):

 for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
    $j = str_replace('%',$i,$pagelink);
    $output .= ' ';//This adds a space before the page number link
    if ( ($i != $page) || ((!$more) && ($page==1)) ) {
        $output .= _wp_link_page($i);
     }
     $output .= $link_before . $j . $link_after;
     if ( ($i != $page) || ((!$more) && ($page==1)) )
        $output .= '</a>';
  }

If you really wanted to get round it, (I don’t recommend this) potentially you could return rather echo the html for the page list and then try to find the spaces using preg_match and remove them.

But really, there is supposed to be a space between the numbers and a so you might want to simply adapt the CSS so that it looks right (as mentioned above these elements have a margin around them).