I believe the wp_link_pages function was made just to list the number of pages within a single post where you can create individual chapters of an article. But it isn’t fully a pagination function where you can have Next & Previous alongside the number of pages.

This code is based on a Bootstrap snippet that allows you to customize the inside of the function’s links as the original code is nowhere as good as the usual pagination function you’d see on WordPress archives.

I can modify for what is has when it comes to changing the links, but I don’t know how to add the next/previous buttons. I’ve looked all over for next/previous for individual posts, but they’re only based on going to the next post, not the next chapter. So I’m hoping someone has already beaten this issue or knows how to get past it with this function here.

function hb_link_pages( $args = array () ) {
    $defaults = array(
        'before'      => '<ul class="pagination">',
        'after'       => '</ul>',
        'before_link' => '<li>',
        'after_link'  => '</li>',
        'current_before' => '',
        'current_after' => '',
        'link_before' => '',
        'link_after'  => '',
        'pagelink'    => '%',
        'echo'        => 1
    );
    $r = wp_parse_args( $args, $defaults );
    $r = apply_filters( 'wp_link_pages_args', $r );
    extract( $r, EXTR_SKIP );
    global $page, $numpages, $multipage, $more, $pagenow;
    if(!$multipage) {
        return;
    }
    $output = $before;
    for($i = 1; $i < ($numpages + 1); $i++) {
        $j       = str_replace( '%', $i, $pagelink );
        $output .= ' ';
        if ($i != $page || (!$more && 1 == $page)) {
            $output .= "{$before_link}" . _wp_link_page( $i ) . "{$link_before}{$j}{$link_after}</a>{$after_link}";
        } else {
            $output .= "{$current_before}{$link_before}<li class='active'><a>{$j}</a></li>{$link_after}{$current_after}";
        }
    }
    print $output . $after;
}

Read more here: Add Next/Previous to custom wp_link_pages


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, ,

Wordpress related questions and answers: