WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my code below I need to close the div "link_wrap" which I created with $args['before'] = '<div id="link_wrap">';

When I try to paste $args['after'] = '</div>'; above return $args; it adds the appropriate closing div but also renders the rest of my code, which allows both previous/next links and pagination, completely useless.

How do I properly close the div while maintaining the functionality of the rest of my code?

// WP_LINK_PAGES: Add prev and next links to a numbered link list
add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');

    function wp_link_pages_args_prevnext_add($args)
    global $page, $numpages, $more, $pagenow;

    $args['before'] = '<div id="link_wrap">';
    $args['link_before'] = '<span class="classlinks">';
    $args['link_after'] = '</span>';

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

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

    return $args;

share|improve this question
up vote 1 down vote accepted

First, declare the after arg at the beginning of your code:

$args['before'] = '<div id="link_wrap">';    
$args['after']  = '</div>';

When there is a next page, the arg is overwritten, so you'll have to add the closing tag at the end:

if ($page<$numpages) # there is a next page
    $args['after'] = ' '. _wp_link_page($page+1)
       . $args['link_before'] . $args['nextpagelink']  . '</a></div>'
share|improve this answer

Your Answer


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.