wp_link_pages()
by default echoes the links (or the output), unless you set the echo
parameter to 0
(or false
). Secondly, your code is returning an array
with nextpagelink
as the only item/value.
But anyway, if you just want the link to the next page, the wp_link_pages()
wouldn’t be the one you should be using since it outputs all the page links (start, next, previous, etc.).
Instead, you can try this, which works well for me:
function nextpage_shortcode( $atts ) {
global $page, $numpages, $multipage;
if ( $multipage ) {
$i = max( 1, $page );
if ( $i < 2 ) {
$text="<span id="next"> BEGIN </span>";
} elseif ( $i < $numpages ) {
$text="<span id="next"> NEXT </span>";
}
if ( ! empty( $text ) ) {
$link = _wp_link_page( $i + 1 );
return $link . $text . '</a>';
}
}
return '';
}
add_shortcode( 'nextpage_short', 'nextpage_shortcode' );
However, you should know that I’m using _wp_link_page()
which is a private function. So you might want to copy the source, rename the function (e.g. to my_link_page
), and use my_link_page()
in the above code.
I hope that helps, and remember that the <!--more-->
tag (i.e. content teaser) is not being taken into account since you’re specifically dealing with the <!--nextpage-->
tag only.