Quantcast
Viewing latest article 1
Browse Latest Browse All 4

Answer by birgire for How to disable content pagination?

New content pagination filter in WordPress 4.4

As of WordPress 4.4 we can use the content_pagination filter ( see ticket #9911 )

/** * Filter the "pages" derived from splitting the post content. * * "Pages" are determined by splitting the post content based on the presence * of `<!-- nextpage -->` tags. * * @since 4.4.0 * * @param array   $pages Array of "pages" derived from the post content. *                       of `<!-- nextpage -->` tags.. * @param WP_Post $post  Current post object. */ $pages = apply_filters( 'content_pagination', $pages, $post );

This filter lives in the setup_postdata() method of the WP_Query class and will make it easier to modify the pagination pages.

Here are few examples how to remove the content pagination (PHP 5.4+):

Example #1

Here's how we can disable the content pagination:

/** * Disable content pagination * * @link http://wordpress.stackexchange.com/a/208784/26350 */add_filter( 'content_pagination', function( $pages ){    $pages = [ join( '', $pages ) ];    return $pages;} );

Example #2

If we want to only target the main query loop:

/** * Disable content pagination in the main loop * * @link http://wordpress.stackexchange.com/a/208784/26350 */add_filter( 'content_pagination', function( $pages ){    if ( in_the_loop() )        $pages = [ join( '', $pages ) ];    return $pages;} );

Example #3

If we only want to target post post type in the main loop:

/** * Disable content pagination for post post type in the main loop * * @link http://wordpress.stackexchange.com/a/208784/26350 */add_filter( 'content_pagination', function( $pages, $post ){    if ( in_the_loop() && 'post' === $post->post_type )        $pages = [ join( '', $pages ) ];    return $pages;}, 10, 2 );

Viewing latest article 1
Browse Latest Browse All 4

Trending Articles