Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

As you can see in my next/previous link I have an extra space before the word "Previous" and I can't seem to find it. Any help is greatly appreciated:

http://themeforward.com/demo2/?p=1813&page=2

Custom function:

// Custom Next/Previous Page
add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');
/**
 * Add prev and next links to a numbered link list
 */
function wp_link_pages_args_prevnext_add($args)
{
    global $page, $numpages, $more, $pagenow;

    if (!$args['next_or_number'] == 'next_and_number') 
        return $args; # exit early

    $args['next_or_number'] = 'number'; # keep numbering for the main part
    if (!$more)
        return $args; # exit early

    if($page-1) # there is a previous page
        $args['before'] .= _wp_link_page($page-1)
            . $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>'
        ;

    if ($page<$numpages) # there is a next page
        $args['after'] = _wp_link_page($page+1)
            . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
            . $args['after']
        ;

    return $args;
}

Calling it:

<?php

wp_link_pages(array(
    'before' => '<p>' . __(''),
    'after' => '</p>',
    'next_or_number' => 'next_and_number', # activate parameter overloading
    'nextpagelink' => __('Next'),
    'previouspagelink' => __('Previous'),
    'pagelink' => '%',
    'echo' => 1 )
);

?>
share|improve this question
    
not a WordPress related problem; a view into the html code in the browser clearly shows no extra space - and using a tool such as the Firefox 'web developer add-on' would quickly reveal css as the cause. –  Michael Jan 18 '12 at 11:55
    
@Michael - it turns out WordPress was responsible –  Stephen Harris Jan 18 '12 at 12:56
add comment

2 Answers

up vote 1 down vote accepted

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).

share|improve this answer
    
That puts a space before the page number, as specified in the question, the problem is a space before the Previous link. You can check out the source code of that page, there is no space before 'Previous' anywhere: <p><a href="http://themeforward.com/demo2/?p=1813">Previous</a> <a href="http://themeforward.com/demo2/?p=1813">1</a> 2</p> . Using Google Chrome's developer tools I can uncheck the CSS rule I stated above, and it realigns the link to where he wants it. –  Jared Jan 18 '12 at 13:05
    
Yes, you're right. I think I jumped to the assumption he was referring to a space after the 'Previous'. –  Stephen Harris Jan 18 '12 at 13:31
    
No problem, looks like you get the vote after all! Lol :) –  Jared Jan 18 '12 at 13:49
add comment

There is a CSS rule margin: 0 5px; on .tags a, I think that is what's causing it to push it right ~1 space.

Also this is off-topic (not related to WordPress specifically).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.