WordPress previous_posts_link() Function

Beginner
6 min read
Updated: Nov 2026
3 examples
Prints a link

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

WordPress
<?php
previous_posts_link( '&laquo; Newer posts' );
CallWhat it does
previous_posts_link()Link with the default text.
previous_posts_link( '&laquo; 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
WordPress
previous_posts_link( string $label = null ): void

Parameters

ParameterDescription
$labelstring. The link text. Default is &laquo; Previous Page.

Return Value

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

WordPress
<div class="pagination">
  <?php previous_posts_link( '&laquo; Newer posts' ); ?>
</div>

How It Works

  1. This sample is page 2, so a newer page exists.
  2. The link points back to page 1.
  3. On page 1 nothing is printed.

Example 2 — Newer and older links

Use it with next_posts_link() for two-way paging.

WordPress
<nav class="pagination">
  <?php previous_posts_link( '&laquo; Newer posts' ); ?>
  <?php next_posts_link( 'Older posts &raquo;' ); ?>
</nav>

How It Works

  1. This sample is page 2 of the list.
  2. previous_posts_link() goes back one page.
  3. 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.

WordPress
<?php
$newer = get_previous_posts_link( 'Newer posts' );
if ( $newer ) {
  echo '<div class="newer">' . $newer . '</div>';
}

How It Works

  1. get_previous_posts_link() returns the link, or null on page 1.
  2. The if makes sure we print the wrapper only when there is a link.
  3. 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

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.

11 people found this page helpful