1

Im currently using the wp_link_pages tag to show the pagination links for content that is split inside the Post. Is there a way to show only the next page link and not all page number links or not show next & previous links? I just want to show only one next page link

  • are you using the main query or a custom one? – bynicolas Aug 11 '16 at 22:17
0

To show prev/next links rather than numbered pagination you need to set the next_or_number argument to next.

Then if you want to remove the previous links, you can filter the HTML for the links with the wp_link_pages filter.

But, you can be craftier and filter on the wp_link_pages_link hook.

Although it is used in a number of contexts, when it is called for the previous link it passes a value representing the page number of the previous page. If you check this against the global $pages, you can come up with the right logic to decide whether you are filtering a "previous" link rather than "next" or numbered pagination.

add_filter( 'wp_link_pages_link', 'wpse_235716_kill_previous', 10, 2);

function wpse_235716_kill_previous( $link, $prev ) {

    global $page;

    if ( $prev > 0 && $prev > $page ) {
        return false;
    } else {
        return $link;
    }

}
  • your filter doesn't work it does the opposite. It kills the next link instead of previous link – Ruriko Aug 13 '16 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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