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.

By default, wp_link_pages (the code which allows you to breakup posts into multiple pages) creates spaces between each number. Is there a way to remove these spaces via functions.php?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Just replace a> <a with a><a:

echo str_replace( 'a> <a', 'a><a', wp_link_pages( array ( 'echo' => FALSE ) ) );

If you want to remove the spaces around unlinked numbers too, I suggest a separate function in your theme’s functions.php to keep the code readable:

function trimmed_link_pages( $args = array () )
{
    $args['echo'] = FALSE;
    $links = wp_link_pages( $args );
    $links = str_replace(
        array ( 'a> ', ' <a', ':<a' ),
        array ( 'a>',  '<a',  ': <a' ),
        $links
    );
    print $links;
}

Use it like wp_link_pages():

if ( have_posts() )
{
    while ( have_posts() )
    {
        the_post();
        print '<h2><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
        the_content();
        trimmed_link_pages();
    }
}

Related: Changing Link Attributes for Wp_Link_Pages.

share|improve this answer
    
That doesn't seem to be working for me, are you simply adding this to functions.php? –  AndrettiMilas Jan 5 '13 at 19:28
    
I am using this instead of the naked wp_link_pages() in a theme. The function does not provide an output filter unfortunately. –  toscho Jan 5 '13 at 19:46
    
Out of curiosity, any idea how to remove the spaces around the current page also... since it is not linked? –  AndrettiMilas Jan 5 '13 at 20:40
    
Thanks, but I actually can't get that new function to work for whatever reason. With my limited PHP knowledge, I assume it should work. How would you implement it? –  AndrettiMilas Jan 5 '13 at 21:03
    
@siouxfan45 See my update. Tested, works. –  toscho Jan 5 '13 at 21:07

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.