WordPress posts_nav_link() Function

Definition
In WordPress, posts_nav_link() prints both paging links for a list of posts: one to the previous (newer) page and one to the next (older) page.
It is an older, all-in-one helper. It works only on lists such as the blog and archives, not on single posts.
Syntax
A few ways to call posts_nav_link().
<?php
posts_nav_link( ' | ', '« Newer', 'Older »' );
| Call | What it does |
|---|
posts_nav_link() | Use the default text and separator. |
posts_nav_link( ' | ' ) | Use a different separator. |
posts_nav_link( ' | ', 'Newer', 'Older' ) | Use your own link texts. |
The order of arguments is separator, previous text, next text. The separator is only shown when both links exist.
Full declaration
posts_nav_link( string $sep = '', string $prelabel = '', string $nxtlabel = '' ): void
Parameters
| Parameter | Description |
|---|
$sep | string. Text between the two links. Default is —. |
$prelabel | string. Text of the previous page link. Default is « Previous Page. |
$nxtlabel | string. Text of the next page link. Default is Next Page ». |
Return Value
| Return Value | Description |
|---|
| void | Nothing is returned. The links are printed. |
WordPress Examples
Three short examples. Each one shows the code and what it prints.
Example 1 — Use the defaults
Print the paging links below the Loop.
<div class="pagination">
<?php posts_nav_link(); ?>
</div>
<div class="pagination">
<a href="https://example.com/" >« Previous Page</a> — <a href="https://example.com/page/3/" >Next Page »</a>
</div>
How It Works
- This sample is page 2 of the list.
- The previous link goes to the newer page 1.
- The next link goes to the older page 3.
Example 2 — Use your own text
Change the separator and both link texts.
<?php posts_nav_link( ' | ', '« Newer posts', 'Older posts »' ); ?>
<a href="https://example.com/" >« Newer posts</a> | <a href="https://example.com/page/3/" >Older posts »</a>
How It Works
- The first argument is the separator.
- The second is the previous (newer) link text.
- The third is the next (older) link text.
Example 3 — On the first page
On page 1 only the next link exists, so the separator is hidden.
<?php posts_nav_link( ' | ', '« Newer posts', 'Older posts »' ); ?>
<a href="https://example.com/page/2/" >Older posts »</a>
How It Works
- There is no newer page, so no previous link is printed.
- The separator shows only when both links exist.
- The same code works on every page of the list.
Frequently Asked Questions
It prints the previous page link and the next page link for a list of posts, in one call.
Separator first, then the previous link text, then the next link text.
No. Use previous_post_link() and next_post_link() for single posts.
Yes. the_posts_navigation() and the_posts_pagination() print more modern markup.
There may be only one page of posts.
Browse all post functions
Open the functions index for simple guides with examples and FAQs.
Post Functions Index →About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful