1

I have this site that uses the <!--nextpage--> tag in posts for pagination purposes. I want to disable pagination, but without deleting the tags for the database (maybe they'll want to use them again in the future).

Tried removing wp_link_pages(); from the template, but then it would only show the first page's content without the links - I don't know if that's how it should work or something wrong.

How can I make it that wordpress simply ignores <!--nextpage--> and display the full post at once?

2 Answers 2

2

You can try to use the the_post filter, to override the content pagination, that takes place within the setup_postdata() function ( PHP 5.4+ ):

/**
 * Ignore the <!--nextpage--> for content pagination.
 * 
 * @see http://wordpress.stackexchange.com/a/183587/26350
 */

add_action( 'the_post', function( $post )
{
    if ( false !== strpos( $post->post_content, '<!--nextpage-->' ) ) 
    {
        // Reset the global $pages:
        $GLOBALS['pages']     = [ $post->post_content ];

        // Reset the global $numpages:
        $GLOBALS['numpages']  = 0;

       // Reset the global $multipage:
        $GLOBALS['multipage'] = false;
    }

}, 99 );

to ignore the <!--nextpage--> feature.

The global $pages variable contains the paginated content:

$pages = explode('<!--nextpage-->', $content);

so that's why we need to restore it to:

$pages = array( $post->post_content );

We actually don't need to restore the $numpages variable, but we do it as part of the house cleaning. If we only restored $pages and $numpages=0 then we would get:

<div class="page-links">Pages:</div>    

The wp_link_pages() function checks if the global $multipage is true to display the content pagination output. So that's the variable to set to false to remove the whole output. We could also use the wp_link_pages filter to remove it.

3
  • Thanks, I was hopeing it would be simpler than adding hooks, but it did work like charm
    – lucian
    Commented Apr 8, 2015 at 14:47
  • Glad to hear it worked for you. Other approach would be to just remove it from the database (or just rename it) with a SQL query. But since you want to have the ability to turn it on again and handle new posts containing it, then I think the filtering solution is more suitable in this case. @LucianDavidescu
    – birgire
    Commented Apr 8, 2015 at 14:59
  • Here's another way to do this via the new content_pagination filter. @LucianDavidescu
    – birgire
    Commented Nov 16, 2015 at 12:15
0

Try to put <?php $GLOBALS['multipage'] = false; ?> in your loop. if doesn't show paginator in mobile:

wp_is_mobile()
$GLOBALS['multipage'] = false;

I hope it is helpful for you

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.