I need to extend the wp_link_page function to only show a max of 5 links at a time. What is the best approach to limit the number of links?

In the end i'd like it to look like this: Previous 1 2 3 4 5 ... Next

I've already used this solution to generate the prev/next buttons along side the numbers.

  • 1
    You're talking about pagination and not about wp_link_pages(). Please do some research before posting.
    – kaiser
    Sep 25, 2012 at 22:44
  • No no no my friend i'm talking about interior post pages using <!--nextpage--> and in that case yes you would use wp_link_pages. Sep 25, 2012 at 23:22
  • The pagination plugin "pagebar" does contains this functionality. You can find it in the repository.
    – Latz
    Oct 4, 2012 at 19:06
  • 1
    Was there ever any progress with this question?
    – kaiser
    Sep 17, 2016 at 20:21
  • I cannot make it works but there might be a way to do this with wp_link_pages_link filter hook. Example: add_filter('wp_link_pages_link', 'hookLinkPagesLink', 11, 2); function hookLinkPagesLink($link, $i) {// your code here} $link is generated href link and $i is current loop. There are also another global variables such as $numpages is total pages, $page is current page.
    – vee
    Mar 24, 2017 at 6:51


Your Answer

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