Ask your WordPress questions! Pay money and get answers fast! (more info)

WP_LINK_PAGES Extra Space (Should Be Easy) WordPress

  • SOLVED

This code allows allows wp_link_pages to display both previous/next links and page numbers. Unfortunately, a problem exists with this code. The "Next Page" link is producing an extra, linked space before the words "Next Page". I need equal spacing between the page numbers and links, but the extra space should not be linked.

<strong>NOTE: THERE NEEDS TO STILL BE A SPACE BEFORE 'NEXT PAGE', THE FIRST ANSWER SIMPLY ACHIEVED WHAT I ALREADY KNOW HOW TO DO - I NEED TO KEEP THE SPACE AND DE-LINK IT, NOT REMOVE IT ALTOGETHER.</strong>

If you can take the code below and change it to give me the code without the space linked, then the money is yours.

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;
}

Answers (1)

2013-01-06

Naveen Chand answers:

Try replacing your code with this code:

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;

}


Naveen Chand comments:

Why not try removing:
. $args['after']


in the last line after '</a>'