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?
1 Answer
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();
}
}
-
That doesn't seem to be working for me, are you simply adding this to functions.php? Commented Jan 5, 2013 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.– fuxia ♦Commented Jan 5, 2013 at 19:46 -
Out of curiosity, any idea how to remove the spaces around the current page also... since it is not linked? Commented Jan 5, 2013 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? Commented Jan 5, 2013 at 21:03
-