I plan to have posts with multiple pages that would receive updates (added pages) over time.

what i want to do is to display the direct link to the last page of the post on the main index.

for example, I have a post split into 4 pages using the tag.

what i want to do is that instead of pagination (which I get using wp_link_pages) that looks like this--> [Page 1 2 3 4]

I'll only get 1 link and get something that looks like this --> [Jump to Page 4]

any way how?

  • Please go and reformat your question. Also show your code. Else there won't be a chance to reopen that question.
    – kaiser
    Commented Jul 28, 2013 at 11:14
  • i don't have a code. i'm asking if there is a code to achieve what i am describing my 'example'...
    – ewanskie
    Commented Jul 28, 2013 at 15:08

1 Answer 1


Crib a bit of code from wp-includes/query.php and bit from wp-includes/post-template.php, add a little, mix and stir, and...

function url_to_last_page() {
  global $post;
  $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $post->post_content);
  $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content);
  $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content);
  $pages = explode('<!--nextpage-->', $content);
  $numpages = count($pages);
  $ret = _wp_link_page($numpages);
  $ret .= $numpages;
  $ret .= '</a>';
  return $ret;
echo url_to_last_page();

wp_list_pages works on index pages so WordPress had to know how to build the links. I just had to find the relevant bits. That need to be inside a Loop, as it depends on the global $post variable. It could be edited to accept a parameter to make it more flexible.

  • sorry, but how do i add this to my theme..? ust new to using wordpress, or rather, new to making my own theme...
    – ewanskie
    Commented May 30, 2013 at 17:03
  • Put the function definition in your theme's function.php and call it where you want the link to display, which is what I did on the last line. It will only work reliably inside a Loop, be aware.
    – s_ha_dum
    Commented May 30, 2013 at 17:05
  • tried it,but nothing happened... :(
    – ewanskie
    Commented Jun 6, 2013 at 14:56
  • 95% sure I tested this... exactly what did you do?
    – s_ha_dum
    Commented Jun 6, 2013 at 14:57
  • uhm here, my index file (pastebin.com/sKNGhvPV), and my functions file (pastebin.com/jebJ6pE8) it won't show anything... if i tinker with the code though, it woud just show the default output of wp_list_pages...
    – ewanskie
    Commented Jun 11, 2013 at 12:55

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.