Post Pagination Customization (wp_link_pages) Editing Navigation

I want to create a post pagination where there is only ONE 'nextpagelink' button per page.

However, I want the text inside the the first 'nextpagelink' to say "WELCOME".

And I want the text inside every 'nextpagelink' after that to say "NEXT PAGE".

Quick Schematic

I figured out the "NEXT PAGE" part:

The following is inside single.php

wp_link_pages( array(
'before' = 'div id="slideshow"',
'after' = '/div',
'next_or_number' = 'next', 
'previouspagelink' = 'span id="previous" style="display:none;" PREVIOUS SLIDE /span',  
'nextpagelink' = 'span id="next" NEXT PAGE /span'
)); ?

The problem is that it makes ALL 'nextpagelink' "NEXT PAGE"

I am trying the following but its not really working:

The following is inside post-template.php

            if ( $next = 1 ) {
            $link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink_first'] . $r['link_after'] . '/a';

Where "nextpagelink_first" = 'WELCOME'

All that does is display 'WELCOME' next to 'NEXT PAGE', and 'WELCOME' always points to first slide, not good.

Please help!

Topic wp-link-pages pagination Wordpress

Category Web


It makes all pages show "NEXT PAGE", because you don't tell it that it should be any different.

What you need is to set that link conditionally based on which page is currently displayed:

wp_link_pages( array(
    'before' => '<div id="slideshow">',
    'after' => '</div>',
    'next_or_number' => 'next', 
    'previouspagelink' => '<span id="previous" style="display:none;"> PREVIOUS SLIDE </span>',  
    'nextpagelink' => ( get_query_var('page') < 2 ) ? '<span id="next"> WELCOME </span>' : '<span id="next"> NEXT PAGE </span>'
) );

This uses a conditional statement:

( get_query_var('page') < 2 ) ? '<span id="next"> WELCOME </span>' : '<span id="next"> NEXT PAGE </span>'

which checks the current page (you can get it by checking page query var) and returning one of the strings based on the condition (here we check if it's the first page or any other).

You can read more on page query var here: What is the difference between $paged and $page?

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.