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.

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

1 Answer 1

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

 
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.