Next/Previous Page Link Plus for WordPress

I do not request donations for my plugins, but if you find this plugin helpful, please visit the plugin directory and give it a 5-star rating. Thanks!


Creates two new template tags for generating next/previous page navigation links.

IMPORTANT: Make sure you are using the right plugin.

The two plugins have similar sounding, but different, function names. If you mistakenly install the wrong plugin, you will get a “call to undefined function” error.


This plugin creates two new template tags — next_page_link_plus and previous_page_link_plus — which may be used to generate next/previous navigation links for pages. The new tags include the following options:

  • Sort the next/previous page links on any column, including alphabetically, by date, and by menu_order.
  • Sort the next/previous links on custom fields (both string and integer sorts are supported).
  • Loop around to the first page if there is no next page (and vice versa).
  • Retrieve the first/last page, rather than the previous/next page (for First|Previous|Next|Last navigation links).
  • Display the featured image alongside the links (WordPress 2.9 or higher).
  • Truncate the link titles to any length, and display custom text in the tooltip.
  • Display the title, date, author, and meta value of the next/previous links.
  • Specify a custom date format for the %date variable.
  • Restrict next/previous links to same parent page, author, or custom field value.
  • Exclude or include individual page IDs.
  • Return multiple next/previous links (e.g. the next N links, in an HTML list).
  • Return the ID, title, date, href attribute, or page object of the next/previous links, instead of echoing them to the screen.
  • Return false if no next/previous link is found, so themes may conditionally display alternate text.

Parameters must be passed either as an array definition (recommended):

<?php next_page_link_plus( array(
'order_by' => 'post_title',
'order_2nd' => 'post_title',
'meta_key' => '',
'loop' => false,
'end_page' => false,
'thumb' => false,
'max_length' => 0,
'format' => '%link &raquo;',
'link' => '%title',
'date_format' => '',
'tooltip' => '%title',
'in_same_parent' => false,
'in_same_author' => false,
'in_same_meta' => false,
'ex_pages' => '',
'in_pages' => '',
'before' => '',
'after' => '',
'num_results' => 1,
'return' => ''
) ); ?>

Or as a URL query style string (the ‘format’ and ‘link’ parameters cannot be specified using a query string, and true and false must be specified as ’1′ and ’0′):

<?php next_page_link_plus('order_by=post_title&meta_key=&loop=0&thumb=0&max_length=0&num_results=1&echo=1'); ?>

The above parameters show the default usage. Note that you need only specify a parameter when you want to override the defaults.



Specifies the primary column that should be used to sort the next/previous page links. The default is post_title (alphabetical order). However, if you are using the Order field to change the page order, or if you are using a page reordering plugin like PageMash, My Page Order, CMS Tree Page View, or Post Types Order, you should set order_by to menu_order:

<?php next_page_link_plus( array('order_by' => 'menu_order') ); ?>

The following are valid values: post_title, post_date, menu_order, post_excerpt, post_name, post_modified, ID, post_author, comment_count. You may also set order_by to ‘custom’ or ‘numeric’ to sort on a custom field (see below).


Specifies the secondary sort column. If the values in the primary sort column are not unique, a secondary sort column is needed to fully sort the pages. Valid values are ID, post_title, post_date, and post_modified (default is post_title).

For example, the following will sort the pages by menu_order first, but if some pages have the same menu_order, it will further sort those pages by title. This ensures that pages with the same menu_order will not be skipped.

<?php next_page_link_plus( array('order_by' => 'menu_order', 'order_2nd' => 'post_title' ) ); ?>


Specifies which custom field to use for a custom sort. Pages not having that custom field are excluded. For example, to sort the next/previous page links on the custom field ‘event_date’:

<?php next_page_link_plus( array('order_by' => 'custom', 'meta_key' => 'event_date') ); ?>

If you want the custom field values to sort as integers rather than strings (for example, if you are storing timestamps in the custom fields, or if you don’t want to zero-pad the numbers), set order_by to ‘numeric’. This forces the custom field values to be converted to data type ‘int’ prior to sorting:

<?php next_page_link_plus( array('order_by' => 'numeric', 'meta_key' => 'event_timestamp') ); ?>

If no meta_key is specified, ‘custom’ is ignored and the function defaults to sorting on post_title.


If loop is set to true (or 1), then the next page link will loop around to the first page if there is no next page (and vice versa). The default is false (no looping). For example, if I want the next page link to lead back to “Alligator” once I get to “Zebra”:

<?php next_page_link_plus( array('order_by' => 'post_title', 'loop' => true) ); ?>


If end_page is set to true, the function will output the ending page in the navigation stream. For previous_page_link_plus, this will be the first page. For next_page_link_plus, it is the last page:

<?php previous_page_link_plus( array('end_page' => true) ); // outputs the first page ?>
<?php next_page_link_plus( array('end_page' => true) ); // outputs the last page ?>

The end_page parameter is primarily used for creating First|Previous|Next|Last navigation links. The default value of end_page is false, so unless you are trying to create First|Last links, you can omit this parameter entirely. In the following example, the First and Last links are created by setting end_page to true:

<?php previous_page_link_plus( array(
'end_page' => true,
'link' => 'First',
) ); ?> |
<?php previous_page_link_plus( array(
'end_page' => false,
'link' => 'Previous',
) ); ?> |
<?php next_page_link_plus( array(
'end_page' => false,
'link' => 'Next',
) ); ?> |
<?php next_page_link_plus( array(
'end_page' => true,
'link' => 'Last',
) ); ?>

By default, end_page does not return a first/last link when the current page is the first/last page. By setting end_page to ‘fixed’, you can force the first/last links to appear even when the first/last page is the current page:

<?php previous_page_link_plus( array(
'end_page' => 'fixed',
'link' => 'First',
) ); ?>

Note that end_page is not compatible with either looping or multiple links. When end_page is set to true, the loop and num_results parameters are disabled.


Displays the featured image alongside the next/previous link. The default is false (no featured image). Note that you may specify the thumbnail size to display. Valid values are true (i.e. the ‘post-thumbnail’ size), as well as all size values accepted by wp_get_attachment_image (e.g. ‘thumbnail’, ‘medium’, ‘large’, ‘full’).

Display the default ‘post-thumbnail’ size image:
<?php next_page_link_plus( array('thumb' => true) ); ?>

Display the ‘medium’ size image:
<?php next_page_link_plus( array('thumb' => 'medium') ); ?>

The thumbnail and link are given CSS classes named ‘page-thumbnail’ and ‘page-link’ to add in styling. By default, they appear next to each other, however if you want the link to appear underneath the thumbnail, add the following styles to your CSS file:

.page-thumbnail { float: left; }
.page-link { float: left; clear: left; }


Truncates the page titles to the nearest whole word under the length you specify, while adding three dots at the end to signify that the title was trimmed. Default is zero (do not truncate). For example:

<?php next_page_link_plus( array('max_length' => 25) ); ?>

This will trim The New York Giants Win Super Bowl XLII in Overtime to The New York Giants Win… The full title will be displayed in the tooltip when the mouse hovers over the link.

format, link

These parameters work the same as described in the WordPress Codex and in this article, with one difference: There are some extra variables that may be used in the ‘format’ parameter to add more information to your links. The %date variable outputs the date the page was published, while the %author variable prints the page author’s display name. For example:

<?php next_page_link_plus( array('link' => '%title', 'format' => '%link (posted on %date by %author)') ); ?>

Produces something like this:

  • (posted on March 23, 2010 by ambrosite)

There is also a %meta variable that may be used only when using a custom sort order, and only when a valid meta_key has been specified. The %meta variable displays the meta_value of the next/previous page:

<?php next_page_link_plus( array('order_by' => 'custom', 'meta_key' => 'event_date', 'format' => '%link (Event date: %meta)') ); ?>

Finally, if you want to get rid of the default “arrows” on the links, remove ‘&laquo;’ and ‘&raquo;’ from the ‘format’ string. See the FAQ for more details.


Specify a date format to customize the display of the %date variable. You may use any of the date and time formats supported by WordPress. For example, to display the date in the format ’2010/11/06 at 12:50 AM’:

<?php next_page_link_plus( array('date_format' => 'Y/m/d \a\t g:i A') ); ?>


Specifies the tooltip text to be displayed when the mouse hovers over the link. By default, the tooltip displays the full title of the page, but you can customize it:

<?php previous_page_link_plus('tooltip' => 'My previous page') ); ?> | <?php next_page_link_plus( array('tooltip' => 'My next page') ); ?>

You may also use the %title, %date, and %author variables in custom tooltip text. For example:

<?php next_page_link_plus( array('tooltip' => '%title posted on %date by %author') ); ?>

Finally, if you want to suppress the tooltip so that it does not pop up at all, set tooltip to false:

<?php next_page_link_plus( array('tooltip' => false) ); ?>


By default, all published pages are included in the next/previous links, regardless of their position in the page hierarchy. However if in_same_parent is set to true, only pages having the same parent page as the current page will be displayed:

<?php next_page_link_plus( array('in_same_parent' => true) ); ?>


Indicates whether or not the next/previous page must have the same author as the current page. If set to true, only pages by the current author will be displayed.

<?php next_page_link_plus( array('in_same_author' => true) ); ?>


Indicates whether or not the next/previous page must have the same custom field value as the current page. You must pass the name of the custom field to be matched. For example, if you had a custom field named ‘publisher’, and you wanted the next/previous links to lead to titles from the same publisher:

<?php next_post_link_plus( array('in_same_meta' => 'publisher') ); ?>

Please note that in_same_meta is not compatible with custom field sorting. If order_by is set to either ‘custom’ or ‘numeric’, in_same_meta is disabled.


Specifies the individual page IDs to be excluded from the next/previous links. Separate multiple page IDs with commas. Any pages you list here will be excluded no matter what the value of the other parameters.

<?php next_page_link_plus( array('ex_pages' => '3,7,12') ); ?>


Specifies the individual page IDs to be included in the next/previous links. Separate multiple page IDs with commas. The pages listed here may be filtered depending on the settings of the other parameters. For example, if you set in_same_parent to true, any pages not having the same parent page as the current page will be excluded even if they are listed in in_pages.

<?php next_page_link_plus( array('in_pages' => '4,5,11') ); ?>

before and after

Text to place before and after the link(s). If no links are found, the before/after text is not displayed. Especially useful for formatting multiple links (see example below).


Returns multiple next/previous links. Default is 1. If this parameter is set to a value greater than 1, the next/previous links will be wrapped in <li> tags; you should surround them with <ul> tags by setting the ‘before’ and ‘after’ parameters. For example:

<?php previous_page_link_plus( array(
'order_by' => 'menu_order',
'format' => '%link',
'link' => '%title',
'before' => '<h4>Previous pages</h4><ul>',
'after' => '</ul>',
'in_same_cat' => true,
'num_results' => 3
) );?>

Causes something like this to be displayed:

Previous pages


If ‘echo’ is set to false, the functions will not echo any output to the screen. Instead, they will return the link(s) as a PHP string. This parameter is deprecated as of version 1.1. Please use the ‘return’ parameter instead.


Specifies what is returned from the functions. For example, if you wanted to retrieve the page ID of the next page, rather than the formatted link:

<?php next_page_link_plus( array('return' => 'id') ); ?>

The following options are supported. If any of these options are set, the functions do not echo anything to the screen, instead they only return the requested value. Please note that ‘object’ and ‘output’ are the only options that work with multiple pages (i.e. num_results > 1).

  • ‘id’ – Return the page ID.
  • ‘title’ – Return the page title.
  • ‘date’ – Return the “published on” date (i.e. the post_date) in the format specified by the date_format parameter.
  • ‘href’ – Return the page permalink (i.e. the value of the href attribute). Useful for those who want to append a query string to the permalink.
  • ‘object’ – Return the page object. If num_results > 1, an array of page objects will be returned.
  • ‘output’ – Return the complete output of the function as a PHP string.

If the ‘return’ parameter is not set, then the functions simply return true or false depending on whether any links were found. This makes it easy to create alternate styles in the event that there is no next/previous page. For example, if you wanted to have grayed out inactive links as described in this article, you can test the return value as follows:

<?php if ( !previous_page_link_plus() ) {
echo '<span class="inactive">&laquo; Previous</span>'; // if there are no previous pages
} ?>

Note that if the $loop parameter is set to true, the function will never return false, since an adjacent page will always be found.

Complete Example

The following pair of template tags cycle through all pages in alphabetical order, with looping, using the default link title and format with custom tooltip text, truncating the title to the nearest whole word under 30 characters, restricting the links to pages having the same parent page as the current page, and excluding page IDs 5 and 12:

<?php previous_page_link_plus( array(
'order_by' => 'post_title',
'loop' => true,
'max_length' => 30,
'tooltip' => 'Previous page',
'in_same_parent' => true,
'ex_pages' => '5, 12'
) );?> |
<?php next_page_link_plus( array(
'order_by' => 'post_title',
'loop' => true,
'max_length' => 30,
'tooltip' => 'Next page',
'in_same_parent' => true,
'ex_pages' => '5, 12'
) );?>


  • Upload ambrosite-page-link-plus.php to the /wp-content/plugins/ directory.
  • Activate the plugin through the Plugins menu in WordPress.
  • Edit your template files, and insert the next_page_link_plus and previous_page_link_plus template tags where you want your next/previous links to be displayed. Configure them using parameters as explained above.

Frequently Asked Questions

How exactly do I install this plugin? Which file needs to be edited, and where do I put the code?

Unfortunately I cannot give specific instructions because every theme is different. In general, you need to find the template file that controls display of pages. This used to be a simple matter of finding the ‘page.php’ file and editing it, but with the proliferation of theme frameworks, child themes, template parts, and action hooks, things have gotten a lot more complicated. If your theme/framework has a community support forum, your best bet is to ask there; otherwise try the support forums at, and be sure to mention which theme you are using.

I am getting a “call to undefined function” error. Why?

First, make sure the plugin is installed and activated before you edit your templates. Verify that the function names are spelled correctly. Also, make sure you are using the right plugin: Next/Previous Page Link Plus is intended for use in page templates, while Next/Previous Post Link Plus is intended for use in single post templates. The two plugins have similar sounding, but different, function names.

If you want to ensure that the functions will never produce a “call to undefined function” error, even if the plugin is deactivated, you can surround them with a ‘function_exists’ check:

<?php if ( function_exists('next_page_link_plus') ) {
next_page_link_plus(); // the function is only called if it is defined
} ?>

How can I get rid of the arrows on my next/previous links?

Technically, the “arrows” are called left and right angle quotes, and they are represented by the ‘&laquo;’ and ‘&raquo;’ HTML entity codes. They appear in the default ‘format’ as follows:

<?php previous_page_link_plus( array('format' => '&laquo; %link') ); ?>
<?php next_page_link_plus( array('format' => '%link &raquo;') ); ?>

If you want to get rid of them, simply remove the entity codes from the ‘format’ string:

<?php previous_page_link_plus( array('format' => '%link') ); ?>
<?php next_page_link_plus( array('format' => '%link') ); ?>

Is this plugin compatible with page reordering plugins like PageMash, My Page Order, CMS Tree Page View, and Post Types Order?

Yes, all of these plugins use the menu_order field to store the page order. All you need to do is set the order_by parameter to menu_order:

<?php next_page_link_plus( array('order_by' => 'menu_order') ); ?>

I am using a custom field with a simple integer value to order my pages, but they’re not sorting correctly. Why?

New answer: Use a ‘numeric’ sort rather than a ‘custom’ sort to convert the custom field values to integers, and they will sort in correct numerical order.

Old answer: You need to zero-pad the integers if you want them to sort numerically. (’001′, ’002′, ’010′, etc.) This is a side effect of the WordPress data design. The ‘meta_value’ field in the wp_postmeta table is defined as type ‘longtext’. This means that any integer stored in the meta_value field is automatically converted into a string. Therefore any sort on the meta_value field is a string sort, not an integer sort. In a string sort, ’10′ comes before ’2′. That is why it is necessary to zero-pad the integers in order to sort them numerically.

I am seeing the number ’1′ printed next to my links. Why?

Several people have reported a mysterious trailing ’1′ appended to their next/previous links. The most likely cause is that you trying to echo the output of next_page_link_plus, like this:

<?php echo next_page_link_plus(); ?>

You don’t need to do that. The function echoes the link to the screen before it returns (assuming you have not set the ‘return’ parameter). The return value of the function is either Boolean true or false, depending on whether a next/previous link was found. When a Boolean ‘true’ is echoed to the screen, it is printed as ’1′. So just get rid of the unnecessary echo, and the problem will be solved.

Is there any way to use an image instead of link text?

Yes, something like this should work:

<?php previous_page_link_plus( array(
'format' => '%link',
'link' => '<img src="images/prev.png" />'
) );?>
<?php next_page_link_plus( array(
'format' => '%link',
'link' => '<img src="images/next.png" />'
) );?>



  • Added ‘in_same_meta’ parameter.
  • Added ‘return’ parameter to specify what should be returned from the function.
  • Added ‘date_format’ parameter for customizing the %date variable.
  • Added %title variable to ‘format’ parameter.
  • Added option to sort on custom fields as integers rather than strings.
  • Added new classes to anchor tags, thumbnails, and list items to aid CSS styling.


  • Initial version.

More Plugins


  1. Sean Carolan says:


    This looks like a great plugin that could be really useful on my site, but I cant seem to make it work. I uploaded and actiavated the plugin, what else must I do to make it work.

    -Sean Carolan

  2. ambrosite says:

    @Sean You need to edit your page template(s), and insert the next_page_link_plus and previous_page_link_plus template tags where you want your next/previous links to be displayed. Please review the documentation; I have provided very thorough instructions and examples.

  3. Josh says:

    A demo?

  4. ambrosite says:

    @Josh What sort of demo are you looking for? This plugin works exactly like Next/Previous Post Link Plus, except it is for pages instead of posts. Look at any WordPress blog that has “Next” and “Previous” post links, and you’ll see what it does.

  5. Michal says:

    I’m having some difficulty with your plugin. I’ve downloaded it and made the changes to the single.php file. I was able to get the navigation to work when defining the post type: ‘ “portfolio” ‘) ); ?> but I couldn’t figure out how to set for taxonomy: ‘my_taxonomy’) ); ?>. I tried a few attempts to enter my taxonomies, but non of my attempts/variations didn’t work.

    I’m trying to get it to work for the following site:

    Some code from the theme:

    function tz_build_taxonomies(){
    $args = array(
    “hierarchical” => true,
    “label” => __( “Skill Types” ),
    “singular_label” => __( “Skill Type” ),
    “rewrite” => array(‘slug’ => ‘furniture’, ‘hierarchical’ => true),
    “public” => true
    register_taxonomy(__( “skill-type” ), array(__( “portfolio” )), $args);

    Would you happen to have any suggestions?
    Entering a list of taxonomies into the php code above, would that work?

    Thanks for your time,

  6. Michal says:

    Hi, I’ve temporarily deactivated the plugin because I’m still not able to get the taxonomies to work. But if you’re able to suggest anything I would like to give it another try.

  7. ambrosite says:

    @Michal I believe you are using the wrong plugin. Page Link Plus does not support taxonomies, because WordPress pages do not use taxonomies, they have hierarchical organization instead. If you have custom post types and taxonomies, you should use this plugin:

  8. Christian says:

    Hi, I would be happy to make work this Plugin. Unfortunatly, as many other people, I’m not used to program files. So…is there anybody who could explain for “non professionals” where all those codes must be installed? What are the specific file names an what is the right position to make work the plugin?
    Thanks a lot,

  9. dominic says:

    hi michael,
    this plugin is, without question, both extremely useful and extremely awesome. i’ve spent the last couple of days trying to create next_post/previous_post links to display on a single-page view of a custom post type which move through the posts alphabetically, but have been failing massively. then i stumbled upon this plugin. less than 2 minutes later the required functionality is in place. utter kudos to you sir. my question – are you likely to ever provide some kind of documentation/explanation/break-down of how one might go about creating next/previous post links manually, without the use of a plugin? if not, well then I reiterate my appreciation. if so, well then my thanks in advance.
    hata luego dude

    dominic B-)

  10. ambrosite says:

    @dominic Thank you for the kind comments about my plugin. I’m not sure what you mean by creating the links “manually”. It is necessary to query the WordPress database in order to find the next/previous links. My plugin contains exactly the code that is required to do this. If you want to see how it works, you can review the source code of the plugin — every section of the code is commented to explain what it does.

  11. Will says:

    Hello, thanks for creating this plugin. I’ve added the tags to my templates, and next_page_link_plus works perfectly with pages ordered by menu_order. However, previous_page_link_plus returns the current page as a link, not the previous page. Any suggestions as to why this might be the case?
    Many thanks,

  12. ambrosite says:

    @Will I don’t know, but if you can give me a link to the site where it is happening, I’ll take a closer look.

  13. Jorgens says:

    Works great on my web. Thanks a lot!

  14. Ryan G says:

    Awesome plugin, thanks. Works great in WP 3.3, and does exactly what I was hoping for. And it seems to have a lot of support features and good documentation (my only advice in your doc would be to put the “installation” section up top, just so beginners don’t get thrown off by all the parameters). I’m using it on my site for navigation on a bunch of sub-pages (and I excluded all the non-subpages).

  15. Jim W says:

    This looks like what I need. However, I’m having a mental block on getting 1 parent page and 4 child pages to work correctly. Each sub-page has the correct parent page. Each sub-page has an order number set 1 to 4. When I go to the parent page (New Athlete’s), the 4 sub-pages don’t show. When I go to the first sub-page, then the prev/next links show. Any idea what I’m doing wrong?

    Thank you, jim

  16. ambrosite says:

    @Jim You would have to tell me what parameters you are using. For example, if you have ‘in_same_parent’ set to TRUE, then the links would show up on the child pages, but not the parent page (assuming you are using the same page template for all pages in the hierarchy). There are other possible causes, but again I need to see your code in order to troubleshoot.

  17. Jason C. Levine says:

    Awesome plugin, works great.

    My only question is styling the output? Possible to add CSS via the array or…?

  18. ambrosite says:

    @Jason What kind of CSS do you want to add? I can see putting a ‘page-link’ class on the <a> tag, and maybe a ‘page-link-item’ class on the <li> tag (if num_results > 1). Is that the sort of thing you are looking for?

  19. Jason C. Levine says:

    Arrgh. I was afraid WP would HTML-ize my comment. Apologies.

  20. ambrosite says:

    @Jason You caught me at just the right time. It so happens that I had planned on releasing a new version of the plugin over the weekend, so I will add some CSS classes as you requested.

  21. Elijah from Russia says:

    Thank you very much! I’m so happy because i finally found it for free. I don’t have time to learn php. But i’m also not a rich person to pay greedy freelancers who pissed me off last time.

  22. Chris says:

    I want to make an image on a page link to the next page per your plugins parameters, is there some way I could apply the a href output of your plugin to other content on my page? Thanks!

  23. ambrosite says:

    @Chris That should be easy enough. Just set the ‘return’ parameter to ‘href’, and capture the return value of the function in a variable. You can then use that variable to create an image link anywhere on your page:

    <a href=”<?php echo $href; ?>”><img src=”my_image.gif”></a>

  24. Jan says:

    I m trying to install the plugin with the wordpress TWENTY ELEVEN (child) theme. Unfortunately I cannot figure out which file(s) I need to add the code to. page/index/function.php??? Anyone done it before? If so…could u pls let me know which files I need to update! THX, Jan

  25. Jan says:

    even before having installes the plugin correctly I have a second question I came across…

    I would want to use the theme’s option of only showing pages “in_same_parent”.

    The problem is that – in the menu – I am using “custom links” (link set to: #) as the main navigation headings as I do not want these to be clickable. Within wordpress I cannot define a “custom link” to become the parent of a page…and therefore I cant really set a reference for the plugin to know which pages to show and which ones not to show…:-(

    Is there a way around that?

  26. Daniel says:

    Hi, thanks for this awesome plugin! Everything goes perfect with the plugin but I have a question. How can I remove the links of some pages of the loop? For example, I don’t want that the next/previous links appear in the “about us” page or “contact” page. I hope you understand my question because English is my second language, thanks for all!!

  27. ambrosite says:

    @Daniel You can use the is_page function to exclude the links from appearing on certain pages. Just set up a conditional check like this:

    if ( ! is_page( array( ‘about-us’, ‘contact’ ) ) {

Comments are closed. If you have a question about this plugin, please create a thread on the WordPress support forum and I will answer it there.