0

I want 'nextpagelink' shortcode [nextpage_shortcode] that I can place inside content.

I've seen threads where they say that you can't place anything related to the wp_link_pages inside content due to the way the content is rendered by Wordpress.

As you can see the text of 'nextpagelink' changes depending on the slide #.

I want the shortcode to reflect that.

Here is the schematic of what I am looking to do:

enter image description here

Both 'BEGIN' buttons link to the 2nd slide.

This is what I am currently working on:

function nextpage_shortcode( $atts ) { wp_link_pages( array(

'before' => '<div id="slideshow">',
'after' => '</div>',
'next_or_number' => 'next', 
'nextpagelink' => ( get_query_var('page') < 2 ) ? '<span id="next"> BEGIN </span>' : '<span id="next"> NEXT </span>' ) );

return ['nextpagelink'];
} add_shortcode( 'nextpage_short', 'nextpage_shortcode' );

Its works somewhat.

Its posts the 'nextpagelink' button above content, but not inside the content.

Not sure how to proceed.

Please help!

2
  • This has been answered at wordpress.stackexchange.com/questions/183978/… Commented Apr 1, 2019 at 22:30
  • Thanks for your response! Correct me I am wrong but the link you've provided simply turns <!--nextpage--> into a shortcode. I don't want [nextpage_shortcode] to actually split content. I want it to refer to the <!--nextpage--> below it.
    – Discover
    Commented Apr 1, 2019 at 22:50

1 Answer 1

0

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.

3
  • Btw, did you mean add_shortcode( 'nextpage_shortcode', 'nextpage_shortcode' ); and not add_shortcode( 'nextpage_short', 'nextpage_shortcode' );? (note the nextpage_short vs nextpage_shortcode)
    – Sally CJ
    Commented Apr 2, 2019 at 3:26
  • Thanks so much! Works Beautifully! I meant the latter. So that the actual shortcode would be [nextpage_short]
    – Discover
    Commented Apr 2, 2019 at 3:36
  • Ah, okay. :) And you're welcome. I'm glad I could help!
    – Sally CJ
    Commented Apr 2, 2019 at 3:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.