Here’s a suggestion, using the wp_link_pages_link
filter to remove the previous links:
add_filter( 'wp_link_pages_link', function( $link, $nextorprev )
{
return get_query_var( 'page' ) > $nextorprev ? '' : $link;
}, 10, 2 );
We can also create a plugin that removes empty previous/next links.
So if we have one of the following:
'nextpagelink' => '',
'nextpagelink' => false,
'nextpagelink' => null,
or
'previouspagelink' => '',
'previouspagelink' => false,
'previouspagelink' => null,
then these links will be removed.
Here’s the skeleton for such a plugin:
<?php
/**
* Plugin Name: Remove Empty Next/Previous Content Pagination Links
* Plugin URI: http://wordpress.stackexchange.com/a/239335/26350
*/
add_filter( 'wp_link_pages_args', function( $args )
{
if( empty( $args['previouspagelink'] ) )
add_filter( 'wp_link_pages_link', 'wpse_remove_prev_links', 10, 2 );
if( empty( $args['nextpagelink'] ) )
add_filter( 'wp_link_pages_link', 'wpse_remove_next_links', 10, 2 );
return $args;
} );
add_filter( 'wp_link_pages', function( $output, $args )
{
if( empty( $args['previouspagelink'] ) )
remove_filter( 'wp_link_pages_link', 'wpse_remove_prev_links', 10, 2 );
if( empty( $args['nextpagelink'] ) )
remove_filter( 'wp_link_pages_link', 'wpse_remove_next_links', 10, 2 );
return $output;
}, 10, 2 );
function wpse_remove_prev_links( $link, $nextorprev )
{
return get_query_var( 'page' ) > $nextorprev ? '' : $link;
}
function wpse_remove_next_links( $link, $nextorprev )
{
return get_query_var( 'page' ) < $nextorprev ? '' : $link;
}
This will not override the default settings, if we leave out the ‘nextpagelink’ or ‘previouspagelink’ arguments.
Here’s a way to add a custom link at the last page:
add_filter( 'wp_link_pages_link', function( $link, $nextorprev ) use ( &$numpages )
{
return get_query_var( 'page' ) === $numpages ? 'CUSTOM LINK' : $link;
}, 11, 2 );
where we have the priority later than in our plugin.