Next Page


This plugin provides shortcodes and template tags for next/previous navigation in pages. This plugin is no longer supported! If you would like to adopt it, please get in touch.

download at get support at

If you’d rather not deal with the overhead of a plugin, here’s the condensed code for your page template file:

$pagelist = get_pages('sort_column=menu_order&#038;sort_order=asc');
$pages = array();
foreach ($pagelist as $apage) {
   $thepages[] += $apage->ID;

$current = array_search($post->ID, $thepages);
$prevID = $thepages[$current-1];
$nextID = $thepages[$current+1];

<div class="navigation">
<?php if (!empty($prevID)) { ?>
<div class="alignleft">
<a href="<?php echo get_permalink($prevID); ?>"
  title="<?php echo get_the_title($prevID); ?>">Previous</a>
<?php }
if (!empty($nextID)) { ?>
<div class="alignright">
<a href="<?php echo get_permalink($nextID); ?>"
 title="<?php echo get_the_title($nextID); ?>">Next</a>
<?php } ?>
</div><!-- .navigation -->

You can emulate Drupal’s book feature and include a link to the page parent as well:

<div class="aligncenter">
<a href="<?php echo get_permalink($post->post_parent); ?>"
 title="<?php echo get_the_title($post->post_parent); ?>">Up one level</a>

Version 1.2 adds an option to exclude pages by ID. You can simply add the exclude parameter to the get_pages() function in your template code:

$pagelist = get_pages('sort_column=menu_order&sort_order=asc&exclude=6,21,47');

154 thoughts on “Next Page

  1. Hey there! This plugin is just what i needed but I installed it and I’m only getting arrows on my posts rather than Previous: Title or Next: Title.

    Is it my theme or must I change some settings?

    Thanks for your time and the great plugin!

  2. TheBeeOBee — sorry I didn’t get back to you sooner; I was on vacation when your comment came in and I overlooked it in my inbox! You should definitely get more than arrows. Can I take a look at the pages in question?

  3. More for TheBeeOBee — are you using the shortcode or the template tag? I’ve just realized that there’s a typo in the template tag shown on the options screen; it should be <?php instead of <php. I’m fixing that in the code now.

  4. Jeff K

    I thought I would have the ability to apply this plug-in to specific set of pages. However, I can’t find any way to be able to this especially in the Atahualpa theme.

    • Jeff, you could use the short tags on the specific pages you want. Otherwise, the template tags would need to go in your theme’s page file, and if you wanted it to show only on a few pages, you’d need to set up some PHP to test the page IDs or something.

  5. Is there a way to get the arrows to show? I only see the text. Is there a way to ONLY get the arrows to show?

    Please let me know. Thank you so much for your help! Talk soon.

  6. Hi Stephanie,
    Thanks so much for the good work. I’ve gone for the code in the page template option, so easy, it’s brilliant!

    Just wondering if I can check a problem with you though…

    I am using another plugin called “page links to” which redirects each main page to the first child page in it’s section. The next buttons are working perfectly because once it hits a redirected page it is redirected, but when I use the previous button it gets stuck on the redirected page. Is there a way I can ask it to skip a page when it comes to that problem. Sorry if it sounds confusing.

    Thanks again,

    • Logan, are you by chance using the Front-end Editor plugin? I’ve noticed that the two conflict for some reason, and when I disable the editor, my arrows show up again. Let me know if that’s not the case for you! Also try version 1.2, which I’ve just uploaded to the plugin repository, and see if that works better for you.

      Belinda, 1.2 includes the page exclusion option. Enjoy!

  7. big will


    i am using your plug-in, but the previous and next buttons link to the post that i am already on. they don’t go to the previous or next post.
    do you know how i can fix this?

    thank you so much!

  8. Is it possible to have the Previous and Next Page links at the bottom of the page rather than on the top? Maybe even have it centered on its own line?
    Thank you.

  9. Wee


    This plugin is working quite nicely for a project of mine. If you have time, I was wondering if you could help me find a way to disable or (preferably) remove/hide the next link when the user comes to the last page in the list. What do you think? I can edit the plugin directly if you can point me in the right direction. Thank you for a great plugin!

  10. Wee

    Hi again :)

    I just realized that I could easily do that using CSS (I heart dynamic body classes). Sorry!! But seriously, this is a very nice, easy-to-implement plugin. You rock.

  11. It’s possible that I’m simply not doing something correctly, but when I activate the plugin, I still don’t see the Previous and Next links on my posts. I’m still very much a noob at WordPress, so maybe there’s something I’m missing on how to implement this plugin. Is there a step-by-step tutorial on exactly what steps to follow in order to get the previous/next links to show up on individual posts?

  12. Stinky: You need to copy the PHP code given on the options screen and paste it somewhere in your theme files. If you have a single.php file, it goes in there.

    Ed, I’m sorry I overlooked your comment. If the links are appearing at the top of the page, you’ve either pasted them there yourself (in which case you can just move them), or you’re confusing these links with WP’s built-in previous/next links for posts, which appear at the top of the page in a lot of themes.

  13. Hi, Stephanie — sorry for sounding thick about this, but where’s the options screen? I’m using the Heatmap for Adsense theme, and it has an options page… but I don’t see anything pertaining to the Next Page plugin there. Am I just missing it somehow?

    Also, does it matter where I paste the php code in the single.php file?

    Thanks for your help!

    • Look under Settings -> Next Page. And yes, it matters: where you paste the code determines where the links appear. I’m not familiar with your theme, but look for a line like < ?php endforeach; ?> or < ?php endwhile; ?> and paste the code just after that. Just experiment until you get the links placed where you want them!

  14. Thanks very much, Stephanie. I’ve got the links where I want them (mostly — I can keep tweaking later). Now, though, I’m having the same trouble as big will — namely, the links are pointing to the page that the user is already on, instead of the next/previous pages.

    Any idea what might be causing this?

  15. Just to clarify, here’s the code I’m using. I’ve got it set directly below the title area, and I set the div alignment within the page, rather than aligning via class in the options page. I’m not using any short code (I’m not sure how to use that, or if I’m supposed to).


    Am I missing something?

  16. You guys, I’m really sorry: I told you the wrong file to put the code in. It should be page.php, not single.php. That’s undoubtedly why the links are not showing up and/or pointing to the current page. I apologize; I’ve been on some weird medications for the last week or so. :(

  17. Hi, Stephanie. Thanks for getting back to me. Unfortunately, when I put the code on my page.php file, it doesn’t appear to be showing up at all now. I’ve tried both the code you provide up top, as well as the direct code listed at the top of the page.

    Because I edited the single.php page, could that be messing with the page.php file and preventing the next/previous navigation from showing up? It does look as though changes to the single.php page are overriding any changes to the page.php file.

    Any thoughts as to why this might not be working? From what I’ve gathered, this should be a fairly simple copy/paste exercise — at least in terms of getting the plugin to function. So I’m at a loss as to what I’m doing incorrectly.

  18. Hey Stephanie. Could the default in WP be interfering with your plugin. Just does not want to work for me yet. How do I deactivate the default nextpage? I liked Chan’s plugin too but could not get it to work.

  19. I have one question, your links go by the alphabet, I have set my pages up with numbers, how do I change the code so the previous and next pages will go to the ones I want according to their number, not their alphabet.

  20. I’ve been using the plugin variety of the above, and it’s great – the one nitpick I had was that when I’m navigating subpages, I don’t want the last page to jump to the next parent page in the hierarchy. So, I fixed that by adding ‘&child_of’ to the flatten_page_list() call and passing in the $post->parent_page.

    Then, instead, the plugin was showing a link to the current page when it was the last one/first one in the list (thereby indicating that nothing followed/preceded it). Fixing that required:

    @ if ($current+1 >= count($pages)) return false; else ….. @


    @ if ($current-1 < 0) return false; else ….. @

    in next_page and prev_page, respectively. I'm not sure if this is the kind of thing anyone else would actually need or want, but for flipping chapters in an online 'book' it was nice to come to a dead stop at the first chapter or the last, instead of leaking over into the next book's hierarchy.

  21. Ed – if you go to the URL above, the next/previous links are on faq, about, and other pages. I don’t want that. Just want them on my courses page (so students can go thru the lessons one at a time). so I put exclude ids but those pages aren’t being excluded.

  22. Hello,

    I am using your plugin and it works except for when I use exclude posts. When I do exclude posts it puts the name and link of the current page for both the next and previous links.

    The install I am working off of is WordPress 2.86 – not sure if you were aware of the bug or not. For my project, it would be ideal if I could select a post parent and have the plugin cycle endlessly through the children. Excluding posts would be ok if it worked.

    Hope you get a fix out there. Thanks.

  23. g.lo

    i show one full post at a time on my front page – so i’m wondering if anyone has adapted this to work with posts instead of pages.

    thanks again for the great plug in. cheers.

  24. I think you need to add to a post to break it down if too long, or else you will have a really long post. That is what I use on my pages and posts when they get too long.

  25. Thanks for a great piece of code. (I’m using the code directly in a page file as opposed to the plugin.)

    The code works perfectly except for the fact it somehow prohibits @@ from rendering. Instead, it displays the page ID. Not sure why this happens. Have you encountered this before?

  26. Oh, sorry. I’ll just state it. It didn’t render “the_content”. It did render everything else on the page, though. And I was wrong about it displaying the page ID. It displays “371″ on each page where “the_content” is supposed to be.

  27. Unfortunately I’m in test mode on the site, so unless I make you an admin, you won’t be able to see it.

    I tried the debugging code you sent me and it appears that the first page in the array has an ID of 371. So somehow it’s printing that in the content area.

    Here’s the printed debug: Array ( [0] => 371 [1] => 368 [2] => 376 [3] => 369 [4] => 370 [5] => 374 [6] => 372 [7] => 373 [8] => 377 [9] => 366 ) Current page ID’s array key: 4Previous page ID: 369Next page ID: 374

    It’s so weird! I have no idea why it would print that in the content. Oh, and I tried moving the entire code after the content, and the content appears fine. So somehow when it appears before the content it’s telling the content to print 371.

  28. It’s not a browser issue that I can see. I’ve tried it on Firefox, Safari and Opera so far and all three have the same problem.

    Thanks for trying to help.

  29. It is not a browser issue. I think I’ve identified the problem, but I’ve been swamped at work today and haven’t had time to test it. Tracy, try changing the $page variable to something else. Apparently it’s a global in WP, which I’d never noticed, and I’m pretty sure that’s the problem.

  30. That’s funny, Stephanie, I was just identifying that as the problem! Yeah, it’s used extensively in the post-template.php file.

    I changed both the $pages and $page variables and it worked.

    Thanks for spending the time to troubleshoot!

  31. @Ed I just changed them to $projectpage and $projectpages respectively because those names mean something to my specific pages. You can change them to whatever you want to though. Just make sure to change the name of all instances of each variable. (I didn’t change the $pagelist variable.)

  32. it was[sic] nice to come to a dead stop at the first chapter or the last, instead of leaking over into the next book’s hierarchy.

    I’ve made 2 changes to this plugin:

    I too ran into the same issue as what Derek states an I think (imho) this in an improvement:

    Slightly changed Code

    The other thing is that I’ve removed the echos from the template tags. Lines 244,248,252 as I want to move the navigation outside the loop. You can put them back in if you wish.

    Hope this helps someone. Excellent plugin!

    • The previous and next links used to be after the text of the page, which is where I want it. Now, after upgrading to 1.4, the links appear after the entry title, but before the text. Also, notice how the beginning of the text is squeezed (wraps around) the previous and next links. I hope this makes sense.

    • The problem began when I upgraded from v. 1.3 to v. 1.4. So the logical conclusion is that something was changed in the plug-in code from 1.3 to 1.4. I’ll just go back to v. 1.3 and hopefully that’ll solve the problem. But thanks for trying, Ed!

  33. When I had the issue it was the script in my template that was over-riding the position of the text. Do you have any other modules in WP installed like WP Page Navi or something? Check your template index file too for scripting conflicts.

  34. Spiritualight


    Im using the shortcodes with next page plugin. It doesnt matter where I put the short codes they always show up at the top of the page above all content. Is there a way of making the next and previous links show up after the content? I can see that this issue has possibly started since the 1.4 release? Where can I get version 1.3 to test and see if that solves it?


  35. Spiritualight


    I found the older version and it works perfectly. The shortcode tags go where I put them and don’t just show up at the top of the page. I’ll be using 1.3 until 1.4 is fixed. Good plugin.. thanks

  36. I’m using the plugin for a site which has kind of a storyline.

    The parent pages are only container pages, containing two to ten subpages. These parent pages should not come up in the navigation. But when I enter those ID’s, no page whatsoever comes up because also the childpages are excluded.



    Pages A and B are empty. The navigation should go from a3 to b1. How can I do this?

  37. I’d like to put my question here for a second time, because the site is now online and I don’t know how to fix my problem (link: The problem is that the backlinks to previous pages is not working in my case. They link to the parent page which is empty, and than nothing happens.

    You can see what I mean here:

  38. i am having a few problems with this plugin. When i add [previous] [parent] and [next]. [previous] and [parent] are grouped together on the same line while [next] is down a line and looks correct. Also i am trying to skip a sub-parent page but not skip the pages under the sub-parent page. is there a way to do that?

  39. Version 2.9.2.
    I’m also using the plugin ‘redirect parent to first child’, but when I disable that plugin, I can go back from b1 to a3 through B, but B is empty. So before getting to page a3 I have to navigate paste an empty page. And I was using this plugin because when I click on parent page B, I want to see b1, and not B, because that’s only a placeholder for the subpages.

    I hope you see my ‘problem’.

  40. Strange. Google Chrome gives me the same problem. I wonder if I made clear enough what my problem is :( I can’t imagine it has something to do with what browser one uses.

  41. Do you think there can be some kind of fix for this? I mean, Internet Explorer is still the browser that is known to be not always correct in handling code and css, no matter what version.

  42. steph

    The plugin works fine in 3.0.

    The problem with the links moving to the top after the 1.4 upgrade is just a CSS issue. If you’re using the alignleft and alignright classes (the default settings), they’re floated left and right, and that pushes them to the top with your content in between. You can fix the problem by either using different classes with different styles, or you can place a clearing element between your content and the next/previous links. For example, you could add <br style=”clear: both”> in front of your before-the-previous-link code.

    I’m still swamped. As soon as I get a few minutes, I’ll release an update that includes an option to insert the clearing tag.

  43. I noticed a small bug in version 1.4. Your functions for placing the links echo the results instead of properly returning the results. Therefore, if you use the shortcodes, the links might show up before the content instead of where the shortcodes are placed. I assume calling the functions directly in PHP would result in expected behavior, though.

    Anyway, thanks for writing the plugin. Hope this helps.

  44. steph

    Everyone, look for version 1.5 in a few minutes. It includes fixes for all the bugs that were reported in 1.4, plus a Belorussian translation by Marcis Gasuns. Thanks for all your comments, and your patience!

  45. Robert

    I just downloaded Next Page 1.5. I installed it in WP and activated it, but I don’t see it on my site at all. I did not play with any of the options as I don’t know what all that stuff is about. I’m a big noob. Can someone help me out??

  46. great plugin!! not many like it.
    i’m having one problem, assuming it’s a CSS thing. but could use a pointer all the same.
    on the following link, you’ll see that the previous shows on the left, and then the “next” also shows on the left. i have it set for alignright in the settings, but it still goes to left.

    here’s the link:

    here’s the section of code in that page template:

    any pointers? thanks!

  47. haha…there’s no better way to discover the solution than to post a comment on a developer’s blog with a question. found the solution w/in 5 minutes after writing question above. i needed to edit the code that goes before the tag to read “right” instead of “alignright” as that’s the wording in my stylesheet. easy enough. thanks for the great plugin!!!

    • Eric

      I noticed this too. I LOVE this plug in, so simple and works pretty much as I want.

      The Exclude Pages works halfway – it doe snot show the “previous” on the page IDs, but it does still show the “next”

      How do we get this to not show either?

  48. Hello! Good plugin!
    But for my project I have made one change in function flatten_page_list:

    function flatten_page_list($exclude = ”) {
    global $post;

    $args = ‘sort_column=menu_order&sort_order=asc&hierarchical=0&parent=’.$post->post_parent;

    Now naviagtion looks like navigation for posts in the same category.
    You do not cycle through ALL pages, but only through pages that have the same parent page.

  49. jon

    I’m using a plug in which show a post within another post. Most navigation plug ins don’t preserve page brakes in the original post when I show that post in another post.
    The “Next Page” shortcode shows the previous and next links from the original post, but they go to my sites home page instead of previous and next pages in the post.
    I’d really appreciate any advise. I’ve been struggling for a solution for a week.

  50. TIM

    Thanks for the plugin. What a life-saver!!

    I made the following change:

    $args = ‘sort_column=post_title&sort_order=asc’

    I’m totally new to WP, so it took a bit of hacking and a bit of luck to find out why my stuff wasn’t paging correctly. Dunno if this affects anyone else…

  51. I’m working on my first WordPress-based website and am trying to set up a previous / next page navigation on it. You will find my website at:

    I have tried your plugin, and your php code installed manually. In both cases I encounter the same problem: the page navigation links gets confused by the blog page. It appears to be confusing individual posts with static pages. I want the navigation to work for just the pages. Can you advise as to how to fix this?

    Many thanks

  52. I’m using this on pages as part of an itinerary with one page per day. It appears that this works only if pages are added in sequential order, as the code gets the next sequential pageid, not necessarily the next chronological day, even if the permalink structure is changed.

    If I add Wednesday’s itinerary after Monday’s itinerary and then add Tuesday’s itinerary, it will not page correctly.

    Any ideas?

  53. Forrest

    Great plugin. Is there any easy way to make it so that it only goes to the previous/next page of a related child page (sibling page)? For example

    Parent >
    Child 1, Child 2, Child 3

    I want it so that it only goes back and forth between Child 1, Child2 & Child 3.


    • Stephanie

      Hi, Mark. You can use the shortcodes in a page’s content, or you can copy the template tags into your theme’s page template. Both the shortcodes and the template tags are shown on the options page.

  54. tgp

    Is it possible to target just the child pages for a parent page? I am working on a site that has hundred of pages, and it will be cumbersome to exclude.


  55. Brent

    Is it possible to have multiple instances of the navigaion on one page. I’m trying to put the prev/next navigation both before and after the content (because the content is really long) and I’m finding that the nav links at the bottom are not the same as the links at the top. Should that be happening?

  56. Hi,
    I just downloaded this plug-in and it seems to be just what I needed, but I’m having a little trouble getting my Global Product List on my homepage to show “Next” and direct my viewers to the list of products on the next page. How do I set that up?
    Please view this website, (, to see the example of how I want my Product Navigation to look on the homepage.
    Will you be able to advise me on how I can do this?

    Thank You,

  57. Gill

    Steph – excellent plugin! I seem to have an error on 2 pages – they take you to wrong [next] page. See:
    And this one has error both [back] and [next] page navigation:

    You can see the widget on the right side with the correct order of all pages.

    I did check the pages id number (it is in right order) as well as date (all in right order). No other pages have this issue, only the 2 pages above…

    Any idea how I could solve this?


  58. is there a way to order and group pages that are the next and pervious?
    I am using it on a store and they would like to group the products in categories. I tried changing the order of the pages and it didn’t change the order of the next and prev. Any ideas. I didn’t remove the page I didn’t want in the list. Thanks for that. but I can’ order the pages. If I could put them in order it would be great.

      • Bob O'Haver

        we tried that and it didn’t seem to work. I tried using the order and I tried resetting the time to change the order and it didn’t seem to work.
        thanks for the response.

        • Gert Kok

          Do pages have parents? The ‘order’ indicates the ordering for pages which have the same parent. ‘Next page’ wil first move on to the children, if any. The children will be processed in order of field ‘order’. This field is `menu_order` in the wp_posts table. Tip: start with an ordering 10,20,30 etc so you can later add some more pages inbetween.

  59. The very handy next-page plugin can be made more generic by adding a parameter in shortcode and template-tags for a custom-post-type, and bring that value into get_pages()
    At lines 189—
    // make the magic happen
    function flatten_page_list($exclude = ”) {
    $args = “sort_column=menu_order&sort_order=asc&post_type={$post_type}”;

  60. Gert Kok

    This change in next-page.php makes the plugin working for custom post types. No need to add the type in the template-tags. I have seen it working with one set of post types, so feedback if this patch is working is welcome

    // make the magic happen
    function flatten_page_list($exclude = ”) {

    global $post;
    $post_type = get_post_type();
    $args = “sort_column=menu_order&sort_order=asc&post_type={$post_type}”;

  61. I am using the Asteroid theme and cannot find a page.php file to insert the template tags. Can you give me any clue as to where I might add them in themes that have no page.php file? Or do I need to stick to themes that have that file?


  62. rado

    Your plug in is not working. Trying to use that for portfolio website to be able switch between pages, but is giving me always other pages except those I need! Ive have excluded pages in setting like for example; about-me, which I don’t want to included and display, but is not doing anything.
    Any idea how to fix that?

  63. lynn

    Hello! I’m trying to get the page title to appear after “Previous” and “Next” but it’s just not happening. Help please?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>