WordPress posts_nav_link() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints two links

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().

WordPress
<?php
posts_nav_link( ' | ', '&laquo; Newer', 'Older &raquo;' );
CallWhat 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
WordPress
posts_nav_link( string $sep = '', string $prelabel = '', string $nxtlabel = '' ): void

Parameters

ParameterDescription
$sepstring. Text between the two links. Default is &#8212;.
$prelabelstring. Text of the previous page link. Default is &laquo; Previous Page.
$nxtlabelstring. Text of the next page link. Default is Next Page &raquo;.

Return Value

Return ValueDescription
voidNothing 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.

WordPress
<div class="pagination">
  <?php posts_nav_link(); ?>
</div>

How It Works

  1. This sample is page 2 of the list.
  2. The previous link goes to the newer page 1.
  3. The next link goes to the older page 3.

Example 2 — Use your own text

Change the separator and both link texts.

WordPress
<?php posts_nav_link( ' | ', '&laquo; Newer posts', 'Older posts &raquo;' ); ?>

How It Works

  1. The first argument is the separator.
  2. The second is the previous (newer) link text.
  3. 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.

WordPress
<?php posts_nav_link( ' | ', '&laquo; Newer posts', 'Older posts &raquo;' ); ?>

How It Works

  1. There is no newer page, so no previous link is printed.
  2. The separator shows only when both links exist.
  3. 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

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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