Only nextpagelink on wp_link_pages

Does someone have a solution to display only the nextpagelink with wp_link_pages in single posts? I’ve tried different solutions, but none of it worked.

As I reach the last page – wp_link_pages remove nextpagelink and show previouspagelink. But I need only nextpagelink at all pages except last one.

Read More

Or maybe a solution to add class for nextpagelink?

Found solution:

<?php global $multipage, $numpages, $page; 
if( $multipage && $page == $numpages )
 {
   //Do nothing
 } else { 
 wp_link_pages('before=&after=&next_or_number=next&previouspagelink=&nextpagelin‌​k=More'); 
} ?>

Related posts

Leave a Reply

1 comment

  1. You’ll have to prepare your own custom function instead of wp_link_pages to use in single.php file of your template.

    Here’s the custom function my_wp_link_pages proposal (contains original wp_link_pages code with commented out lines):

    function my_wp_link_pages($args = '') {
        $defaults = array(
            'before' => '<p>' . __('Pages:'), 'after' => '</p>',
            'link_before' => '', 'link_after' => '',
            /*'next_or_number' => 'number',*/ 'nextpagelink' => __('Next page'),
            'previouspagelink' => __('Previous page'), '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;
    
        $output = '';
        if ( $multipage ) {
            if ( 'number' == $next_or_number ) {
                $output .= $before;
                for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
                    $j = str_replace('%',$i,$pagelink);
                    $output .= ' ';
                    if ( ($i != $page) || ((!$more) && ($page==1)) ) {
                        $output .= _wp_link_page($i);
                    }
                    $output .= $link_before . $j . $link_after;
                    if ( ($i != $page) || ((!$more) && ($page==1)) )
                        $output .= '</a>';
                }
                $output .= $after;
            } else {
                if ( $more ) {
                    $output .= $before;
                    /*$i = $page - 1;
                    if ( $i && $more ) {
                        $output .= _wp_link_page($i);
                        $output .= $link_before. $previouspagelink . $link_after . '</a>';
                    }*/
                    $i = $page + 1;
                    if ( $i <= $numpages && $more ) {
                        $output .= _wp_link_page($i);
                        $output .= $link_before. $nextpagelink . $link_after . '</a>';
                    }
                    $output .= $after;
                }
            }
        }
    
        if ( $echo )
            echo $output;
    
        return $output;
    }