WordPress previous_posts_link() Function

Definition
In WordPress, previous_posts_link() prints a link to the previous page of posts. On a blog or archive page, this is the link back to newer posts.
Use it with next_posts_link() to add paging below a list of posts.
Syntax
A few ways to call previous_posts_link().
<?php
previous_posts_link( '« Newer posts' );
| Call | What it does |
|---|
previous_posts_link() | Link with the default text. |
previous_posts_link( '« Newer posts' ) | Link with your own text. |
get_previous_posts_link() | Return the link instead of printing it. |
It prints the link. On the first page there is nothing newer, so nothing is printed.
Full declaration
previous_posts_link( string $label = null ): void
Parameters
| Parameter | Description |
|---|
$label | string. The link text. Default is « Previous Page. |
Return Value
| Return Value | Description |
|---|
| void | Nothing is returned. The link is printed, or nothing on the first page. |
WordPress Examples
Three short examples. Each one shows the code and what it prints.
Example 1 — Newer posts link
Place it after the Loop on the blog page.
<div class="pagination">
<?php previous_posts_link( '« Newer posts' ); ?>
</div>
<div class="pagination">
<a href="https://example.com/" >« Newer posts</a>
</div>
How It Works
- This sample is page 2, so a newer page exists.
- The link points back to page 1.
- On page 1 nothing is printed.
Example 2 — Newer and older links
Use it with next_posts_link() for two-way paging.
<nav class="pagination">
<?php previous_posts_link( '« Newer posts' ); ?>
<?php next_posts_link( 'Older posts »' ); ?>
</nav>
<nav class="pagination">
<a href="https://example.com/page/1/" >« Newer posts</a>
<a href="https://example.com/page/3/" >Older posts »</a>
</nav>
How It Works
- This sample is page 2 of the list.
previous_posts_link() goes back one page.next_posts_link() goes forward one page.
Example 3 — Return the link with get_previous_posts_link()
Store the link in a variable and print it only if it exists.
<?php
$newer = get_previous_posts_link( 'Newer posts' );
if ( $newer ) {
echo '<div class="newer">' . $newer . '</div>';
}
<div class="newer"><a href="https://example.com/" >Newer posts</a></div>
How It Works
get_previous_posts_link() returns the link, or null on page 1.- The
if makes sure we print the wrapper only when there is a link. - This avoids empty boxes on the first page.
Frequently Asked Questions
It prints a link to the previous page of a posts list. That is usually the newer posts.
previous_posts_link() moves between list pages. previous_post_link() moves between single posts.
You are probably on the first page, so there is no previous page.
Pass your text as the first argument.
next_posts_link() prints the link to the next (older) page.
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.
11 people found this page helpful